public AuthorityTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env) { InitializeComponent(); _ctc = ctc; _ctcgui = ctcgui; _env = env; }
/// <summary> /// Constructor for the Train GUI. /// </summary> /// <param name="environment">The environment being used by the entire simulation.</param> public TrainGUI(ISimulationEnvironment environment) { InitializeComponent(); _dropDownOpen = false; _GUIPaused = false; allTrainComboBox.SelectedIndexChanged += allTrainComboBox_SelectedIndexChanged; _allTrains = environment.AllTrains; _numTrains = _allTrains.Count; _timer = 0; PopulateComboBox(_allTrains); if (_allTrains != null && _allTrains.Count > 0) { _selectedTrain = (Train)_allTrains[0]; allTrainComboBox.SelectedItem = _selectedTrain; } UpdateGUI(); _environment = environment; _environment.Tick += _environment_Tick; }
//The constructor for the dispatch public Dispatch(ISimulationEnvironment env, string id, string time, string type, string color, string route) { //Store all incoming data to our global variables _environment = env; _dispatchTime = DateTime.Parse(time); _dispatchID = int.Parse(id); _routeType = int.Parse(type); _color = color; //Create our route object based on whether or not this is a custom route if (_routeType == 0) { var stops = new List<IBlock>(); IBlock last = null; foreach (string blockID in route.Split('|')) { stops.Add(_environment.TrackModel.requestBlockInfo(int.Parse(blockID), _color)); last = _environment.TrackModel.requestBlockInfo(int.Parse(blockID), _color); } _dispatchRoute = new Route(RouteTypes.PointRoute, last, -1, stops); } else { _dispatchRoute = new Route(RouteTypes.DefinedRoute, null, int.Parse(route), null); } }
public TrainController(ISimulationEnvironment env, ITrainModel tm) { _environment = env; _environment.Tick += _environment_Tick; _tcGUI = null; Train = tm; _log = ""; _announcements = new Dictionary <int, string>(); _announcements.Add(8, "Arrived at Shadyside Station\r\n"); _announcements.Add(16, "Arrived at Herron Station\r\n"); _announcements.Add(21, "Arrived at Swissville Station\r\n"); _announcements.Add(25, "Arrived at Penn Station\r\n"); _announcements.Add(35, "Arrived at Steel Plaza Station\r\n"); _announcements.Add(45, "Arrived at First Avenue Station\r\n"); _announcements.Add(60, "Arrived at South Hills Junction\r\n"); _announcements.Add(2, "Arrived at Pioneer Station\r\n"); _announcements.Add(9, "Arrived at Edgebrook Station\r\n"); _announcements.Add(22, "Arrived at Whited Station\r\n"); _announcements.Add(31, "Arrived at South Bank Station\r\n"); _announcements.Add(39, "Arrived at Central Station\r\n"); _announcements.Add(48, "Arrived at Inglewood Station\r\n"); _announcements.Add(57, "Arrived at Overbrook Station\r\n"); _announcements.Add(65, "Arrived at Glenbury Junction\r\n"); _announcements.Add(73, "Arrived at Dormont Station\r\n"); _announcements.Add(77, "Arrived at Mt. Lebanon Station\r\n"); _announcements.Add(96, "Arrived at Castle Shannon Station\r\n"); _announcements.Add(105, "Arrived at Dormont Station\r\n"); _announcements.Add(114, "Arrived at Glenbury Junction\r\n"); _announcements.Add(123, "Arrived at Overbrook Station\r\n"); _announcements.Add(132, "Arrived at Inglewood Station\r\n"); _announcements.Add(141, "Arrived at Central Station\r\n"); }
/// <summary> /// Default Constructor /// </summary> public SystemLog(ISimulationEnvironment e) { _currentLogFile = "Terminal_Velocity.log"; _env = e; _env.Tick += new EventHandler<Utility.TickEventArgs>(_env_Tick); _messages = new Queue(); }
public TrackControllerUi(ISimulationEnvironment e, ITrackController primary) { _current = (TrackController)primary; _primary = (TrackController)primary; _trains = Tc.Trains; _blocks = Tc.Blocks; _routes = Tc.Routes; InitializeComponent(); ITrackController c = _primary; while (c != null) { tcComboBox.Items.Add(string.Format("Track Controller {0}", c.ID)); tcCountBox.Text = string.Format("{0} Track Controllers", c.ID + 1); c = c.Next; } okButton.Click += OkButtonClick; tcCountBox.BackColor = (String.Compare(_primary.Line, "Green", StringComparison.Ordinal) == 0) ? Color.Green : Color.Red; tcCountBox.ForeColor = Color.White; _tickCount = 0; e.Tick += ETick; Draw(); }
public TrackControllerUi(ISimulationEnvironment e, ITrackController primary) { _current = (TrackController) primary; _primary = (TrackController) primary; _trains = Tc.Trains; _blocks = Tc.Blocks; _routes = Tc.Routes; InitializeComponent(); ITrackController c = _primary; while (c != null) { tcComboBox.Items.Add(string.Format("Track Controller {0}", c.ID)); tcCountBox.Text = string.Format("{0} Track Controllers", c.ID + 1); c = c.Next; } okButton.Click += OkButtonClick; tcCountBox.BackColor = (String.Compare(_primary.Line, "Green", StringComparison.Ordinal) == 0) ? Color.Green : Color.Red; tcCountBox.ForeColor = Color.White; _tickCount = 0; e.Tick += ETick; Draw(); }
//The contructor for our dispatch database public DispatchDatabase(ISimulationEnvironment env, string filename) { //Store all incoming data to our globals _environment = env; _filename = filename; _successfulParse = ParseFile(_filename); }
public TestingTrackModel(ISimulationEnvironment env) { _env = env; _redBlocks = new List <IBlock>(); _greenBlocks = new List <IBlock>(); IBlock r0 = new TestingBlock("Red", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock r1 = new TestingBlock("Red", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock r2 = new TestingBlock("Red", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy); IBlock r3 = new TestingBlock("Red", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy); IBlock r4 = new TestingBlock("Red", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy); IBlock r5 = new TestingBlock("Red", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy); IBlock r6 = new TestingBlock("Red", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy); _redBlocks.Add(r0); _redBlocks.Add(r1); _redBlocks.Add(r2); _redBlocks.Add(r3); _redBlocks.Add(r4); _redBlocks.Add(r5); _redBlocks.Add(r6); _redLineLayout = new IBlock[1, 7]; _redLineLayout[0, 0] = r0; _redLineLayout[0, 1] = r1; _redLineLayout[0, 2] = r2; _redLineLayout[0, 3] = r3; _redLineLayout[0, 4] = r4; _redLineLayout[0, 5] = r5; _redLineLayout[0, 6] = r6; _redPath = _redBlocks.ToArray(); IBlock g0 = new TestingBlock("Green", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock g1 = new TestingBlock("Green", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock g2 = new TestingBlock("Green", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy); IBlock g3 = new TestingBlock("Green", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy); IBlock g4 = new TestingBlock("Green", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy); IBlock g5 = new TestingBlock("Green", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy); IBlock g6 = new TestingBlock("Green", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy); _greenBlocks.Add(g0); _greenBlocks.Add(g1); _greenBlocks.Add(g2); _greenBlocks.Add(g3); _greenBlocks.Add(g4); _greenBlocks.Add(g5); _greenBlocks.Add(g6); _greenLineLayout = new IBlock[1, 7]; _greenLineLayout[0, 0] = g0; _greenLineLayout[0, 1] = g1; _greenLineLayout[0, 2] = g2; _greenLineLayout[0, 3] = g3; _greenLineLayout[0, 4] = g4; _greenLineLayout[0, 5] = g5; _greenLineLayout[0, 6] = g6; _greenPath = _greenBlocks.ToArray(); }
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 TestingTrackModel(ISimulationEnvironment env) { _env = env; _redBlocks = new List<IBlock>(); _greenBlocks = new List<IBlock>(); IBlock r0 = new TestingBlock("Red", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock r1 = new TestingBlock("Red", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock r2 = new TestingBlock("Red", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy); IBlock r3 = new TestingBlock("Red", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy); IBlock r4 = new TestingBlock("Red", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy); IBlock r5 = new TestingBlock("Red", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy); IBlock r6 = new TestingBlock("Red", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy); _redBlocks.Add(r0); _redBlocks.Add(r1); _redBlocks.Add(r2); _redBlocks.Add(r3); _redBlocks.Add(r4); _redBlocks.Add(r5); _redBlocks.Add(r6); _redLineLayout = new IBlock[1, 7]; _redLineLayout[0, 0] = r0; _redLineLayout[0, 1] = r1; _redLineLayout[0, 2] = r2; _redLineLayout[0, 3] = r3; _redLineLayout[0, 4] = r4; _redLineLayout[0, 5] = r5; _redLineLayout[0, 6] = r6; _redPath = _redBlocks.ToArray(); IBlock g0 = new TestingBlock("Green", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock g1 = new TestingBlock("Green", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy); IBlock g2 = new TestingBlock("Green", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy); IBlock g3 = new TestingBlock("Green", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy); IBlock g4 = new TestingBlock("Green", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy); IBlock g5 = new TestingBlock("Green", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy); IBlock g6 = new TestingBlock("Green", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy); _greenBlocks.Add(g0); _greenBlocks.Add(g1); _greenBlocks.Add(g2); _greenBlocks.Add(g3); _greenBlocks.Add(g4); _greenBlocks.Add(g5); _greenBlocks.Add(g6); _greenLineLayout = new IBlock[1, 7]; _greenLineLayout[0, 0] = g0; _greenLineLayout[0, 1] = g1; _greenLineLayout[0, 2] = g2; _greenLineLayout[0, 3] = g3; _greenLineLayout[0, 4] = g4; _greenLineLayout[0, 5] = g5; _greenLineLayout[0, 6] = g6; _greenPath = _greenBlocks.ToArray(); }
/// <summary> /// Default Constructor /// </summary> public SystemLog(ISimulationEnvironment e) { _currentLogFile = "Terminal_Velocity.log"; _env = e; _env.Tick += new EventHandler <Utility.TickEventArgs>(_env_Tick); _messages = new Queue(); }
public TrainController(ISimulationEnvironment env, ITrainModel tm) { _environment = env; _environment.Tick += _environment_Tick; _tcGUI = null; Train = tm; _log = ""; _announcements = new Dictionary<int, string>(); _announcements.Add(8, "Arrived at Shadyside Station\r\n"); _announcements.Add(16, "Arrived at Herron Station\r\n"); _announcements.Add(21, "Arrived at Swissville Station\r\n"); _announcements.Add(25, "Arrived at Penn Station\r\n"); _announcements.Add(35, "Arrived at Steel Plaza Station\r\n"); _announcements.Add(45, "Arrived at First Avenue Station\r\n"); _announcements.Add(60, "Arrived at South Hills Junction\r\n"); _announcements.Add(2, "Arrived at Pioneer Station\r\n"); _announcements.Add(9, "Arrived at Edgebrook Station\r\n"); _announcements.Add(22, "Arrived at Whited Station\r\n"); _announcements.Add(31, "Arrived at South Bank Station\r\n"); _announcements.Add(39, "Arrived at Central Station\r\n"); _announcements.Add(48, "Arrived at Inglewood Station\r\n"); _announcements.Add(57, "Arrived at Overbrook Station\r\n"); _announcements.Add(65, "Arrived at Glenbury Junction\r\n"); _announcements.Add(73, "Arrived at Dormont Station\r\n"); _announcements.Add(77, "Arrived at Mt. Lebanon Station\r\n"); _announcements.Add(96, "Arrived at Castle Shannon Station\r\n"); _announcements.Add(105, "Arrived at Dormont Station\r\n"); _announcements.Add(114, "Arrived at Glenbury Junction\r\n"); _announcements.Add(123, "Arrived at Overbrook Station\r\n"); _announcements.Add(132, "Arrived at Inglewood Station\r\n"); _announcements.Add(141, "Arrived at Central Station\r\n"); }
public CTC_Dummy(ISimulationEnvironment env) { _env = env; _env.Tick += new EventHandler <TickEventArgs>(_env_Tick); _start = false; _stop = false; _requestCount = 0; }
public CTC_Dummy(ISimulationEnvironment env) { _env = env; _env.Tick += new EventHandler<TickEventArgs>(_env_Tick); _start = false; _stop = false; _requestCount = 0; }
//Contructor for the add and edit dispatch GUI public AddEditGUI(ISimulationEnvironment env, DispatchDatabase dispatchDatabase, bool isEdit, string[] data) { //Store all incoming information to our globals _environment = env; _dispatchDatabase = dispatchDatabase; _incomingData = data; _isEdit = isEdit; //Load up the form InitializeComponent(); //If this is an edit if (isEdit) { //Prepopulate the fields in the form with information //Time of dispatch DateTime tempDateTime = DateTime.Parse(data[1]); cmbHour.SelectedIndex = (tempDateTime.Hour%12) - 1; //Round to closest 15 minute interval cmbMinute.SelectedIndex = (tempDateTime.Minute/15); //Select the right line (green or red) if (data[3].Equals("Red")) { cmbSelect.SelectedIndex = 0; } else { cmbSelect.SelectedIndex = 1; } //Select AM or PM if (tempDateTime.Hour > 11) { cmbAMPM.SelectedIndex = 1; } else { cmbAMPM.SelectedIndex = 0; } //Select custom or predefined route if (int.Parse(data[2]) == 0) { rdbDefined.Checked = false; rdbCustom.Checked = true; txtCustom.Text = data[4]; } else { rdbDefined.Checked = true; rdbCustom.Checked = false; cmbSelect.SelectedIndex = int.Parse(data[4]); } } }
public TestingTrackController(int id, TestingTrackModel tm, ISimulationEnvironment env, bool gui) { _id = id; _blocks = new List <IBlock>(); _trains = new List <ITrainModel>(); _tm = tm; _env = env; _gui = gui; }
public TestingTrackController(int id, TestingTrackModel tm, ISimulationEnvironment env, bool gui) { _id = id; _blocks = new List<IBlock>(); _trains = new List<ITrainModel>(); _tm = tm; _env = env; _gui = gui; }
//Constructor public TrackModelGUI(ISimulationEnvironment env, TrackModel tm) { //var initialization _environment = env; _tm = tm; //Subscribe to an environment Tick //_environment.Tick += new EventHandler<TickEventArgs>(_environment_Tick); //Component initialization InitializeComponent(); }
//The constructor for the GUI public SystemSchedulerGUI(ISimulationEnvironment env, SystemScheduler systemScheduler, ICTCOffice ctc) { //Get everything up and running on the form InitializeComponent(); //Copy all of our incoming data to our globals _environment = env; _ctcOffice = ctc; _systemScheduler = systemScheduler; //Subscribed to the environment tick event _environment.Tick += EnvironmentTickHandler; }
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"); } }
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
public RoutingTool(CTCOfficeGUI ctcgui, CTCOffice ctc, ISimulationEnvironment env, IBlock sBlock, bool mode) { InitializeComponent(); //mode = true for dispatch, mode = flase for update _btnPoint.Enabled = !mode; _ctc = ctc; _ctcGui = ctcgui; _env = env; _startBlock = sBlock; _ctcGui.RoutingToolResponse += _ctcGui_RoutingToolResponse; _endBlock = null; }
public TrackCircuit(ISimulationEnvironment env, List<IBlock> blocks) { _trains = new Dictionary<int, ITrainModel>(); _blocks = new Dictionary<int, IBlock>(); foreach (var b in blocks) _blocks.Add(b.BlockID, b); if (blocks.Count > 0) _line = blocks[0].Line; else _line = "Red"; _env = env; _env.Tick += EnvTick; }
/// <summary> /// This constructor is used when passenger, crew, and temperature information is not given. /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius. /// </summary> /// <param name="trainID">The ID to give to the train.</param> /// <param name="startingBlock">The starting block of the train.</param> /// <param name="environment">The environment being used by the entire simulation.</param> public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment) { _environment = environment; _environment.Tick += _environment_Tick; _trainID = trainID; _totalMass = calculateMass(); _informationLog = ""; _informationCount = 0; _lightsOn = false; _doorsOpen = false; _temperature = 32; _currentAcceleration = 0; _currentVelocity = 0; _currentPosition = 0; _numPassengers = 0; _numCrew = 0; _brakeFailure = false; _engineFailure = false; _signalPickupFailure = false; _emergencyBrakePulled = false; _positionWarningGiven = false; _velocityWarningGiven = false; _accelerationWarningGiven = false; _decelerationWarningGiven = false; _currentBlock = startingBlock; _previousBlockID = 0; _currentBlockID = _currentBlock.BlockID; _blockLength = _currentBlock.BlockSize; _trackCircuitID = _currentBlock.TrackCirID; _trackModel = environment.TrackModel; _trainController = new TrainController.TrainController(_environment, this); // set allTrains equal to list contained in environment allTrains = environment.AllTrains; _timeInterval = (environment.GetInterval() / 1000.0); appendInformationLog("Created on block " + _currentBlockID + "."); }
private const int _maxCapacity = 222; // 74 seated, 148 standing #endregion #region Constructors /// <summary> /// This constructor is used when passenger, crew, and temperature information is not given. /// It adds no passengers or crew and sets the temperature equal to 32 degrees Celcius. /// </summary> /// <param name="trainID">The ID to give to the train.</param> /// <param name="startingBlock">The starting block of the train.</param> /// <param name="environment">The environment being used by the entire simulation.</param> public Train(int trainID, IBlock startingBlock, ISimulationEnvironment environment) { _environment = environment; _environment.Tick += _environment_Tick; _trainID = trainID; _totalMass = calculateMass(); _informationLog = ""; _informationCount = 0; _lightsOn = false; _doorsOpen = false; _temperature = 32; _currentAcceleration = 0; _currentVelocity = 0; _currentPosition = 0; _numPassengers = 0; _numCrew = 0; _brakeFailure = false; _engineFailure = false; _signalPickupFailure = false; _emergencyBrakePulled = false; _positionWarningGiven = false; _velocityWarningGiven = false; _accelerationWarningGiven = false; _decelerationWarningGiven = false; _currentBlock = startingBlock; _previousBlockID = 0; _currentBlockID = _currentBlock.BlockID; _blockLength = _currentBlock.BlockSize; _trackCircuitID = _currentBlock.TrackCirID; _trackModel = environment.TrackModel; _trainController = new TrainController.TrainController(_environment, this); // set allTrains equal to list contained in environment allTrains = environment.AllTrains; _timeInterval = (environment.GetInterval() / 1000.0); appendInformationLog("Created on block " + _currentBlockID + "."); }
//The constructor for the system scheduler public SystemScheduler(ISimulationEnvironment env, ICTCOffice ctc) { //Store all of the incoming data to our globals _env = env; _ctc = ctc; //Get the current time _currentTime = DateTime.Now; _currentTime.AddMilliseconds(_currentTime.Millisecond * -1); //Subscribed to the environment tick event _env.Tick += _environment_Bollocks; //Also listen for when we are asked to start and stop _ctc.StartAutomation += _ctc_StartAutomation; _ctc.StopAutomation += _ctc_StopAutomation; }
/// <summary> /// A constructor for the TrackModel module /// </summary> /// <param name="environment">Requires a reference to the surrounding environment object</param> public TrackModel(ISimulationEnvironment environment) { _redLoaded = false; _greenLoaded = false; _env = environment; _dbCreator = new DBCreator("", environment); _dbManager = new DBManager(_dbCreator.DBCon); _changeState = TrackChanged.None; IBlock redTemp = requestBlockInfo(1, "Red"); IBlock greenTemp = requestBlockInfo(1, "Green"); if (redTemp != null) { List <IBlock>[] tempBlockList = createBlockListArray(0); _dbCreator.populateTCs(tempBlockList, true); _changeState = TrackChanged.Red; _redLoaded = true; } if (greenTemp != null) { List <IBlock>[] tempBlockList = createBlockListArray(1); _dbCreator.populateTCs(tempBlockList, false); if (_changeState == TrackChanged.Red) { _changeState = TrackChanged.Both; } else { _changeState = TrackChanged.Green; } _greenLoaded = true; } if (_changeState != TrackChanged.None) { alertTrackChanged(); } //_environment.Tick+= }
/// <summary> /// A public constructor allowing external modules or TrackModel to create DBCreator objects /// </summary> /// <param name="fPath">The filepath to the database to connect to</param> public DBCreator(string fPath, ISimulationEnvironment environment) { circuits = new List <ITrackCircuit>(); _env = environment; //fPath is the filename of the database to connect to. //Check filepath's legit'ness, give it the default otherwise if (fPath == null || fPath.Equals("")) { fPath = "trackDatabase.db"; } //Check if the database file exists (before you create it). If it does, we need //to CREATE the necessary tables bool needsInitFlag = false; if (!File.Exists(fPath)) { needsInitFlag = true; } //Create a db connection (creating the db file if it doesnt already exist) //string connectionString = "Data Source=" + fPath; string connectionString = "Data Source=" + Path.GetDirectoryName(Application.ExecutablePath) + @"\" + fPath; _dbCon = new SQLiteConnection(connectionString); //If you needed to create the db tables,do so now if (needsInitFlag) { //Console.WriteLine("About to enter initDB"); int initResult = initDB(); //If creating the db failed if (initResult == -1) { _dbCon = null; } } }
/// <summary> /// Constructs a new instance of the TrackController class /// </summary> /// <param name="env">A reference to the global environment object</param> /// <param name="circuit">A track circuit for the track controller</param> public TrackController(ISimulationEnvironment env, ITrackCircuit circuit) { _trains = new Dictionary<int, ITrainModel>(); _blocks = new Dictionary<int, IBlock>(); _routes = new Dictionary<int, List<IBlock>>(); _updateBlocks = new Dictionary<int, IBlock>(); _env = env; _env.Tick += EnvTick; ID = -1; SetId(); _circuit = circuit; _circuit.ID = ID; // PROTOTYPE - static PLC _plc = new Plc(_env, _circuit); _messages = new List<string>(); }
/// <summary> /// Constructs a new instance of the TrackController class /// </summary> /// <param name="env">A reference to the global environment object</param> /// <param name="circuit">A track circuit for the track controller</param> public TrackController(ISimulationEnvironment env, ITrackCircuit circuit) { _trains = new Dictionary <int, ITrainModel>(); _blocks = new Dictionary <int, IBlock>(); _routes = new Dictionary <int, List <IBlock> >(); _updateBlocks = new Dictionary <int, IBlock>(); _env = env; _env.Tick += EnvTick; ID = -1; SetId(); _circuit = circuit; _circuit.ID = ID; // PROTOTYPE - static PLC _plc = new Plc(_env, _circuit); _messages = new List <string>(); }
public TrackCircuit(ISimulationEnvironment env, List <IBlock> blocks) { _trains = new Dictionary <int, ITrainModel>(); _blocks = new Dictionary <int, IBlock>(); foreach (var b in blocks) { _blocks.Add(b.BlockID, b); } if (blocks.Count > 0) { _line = blocks[0].Line; } else { _line = "Red"; } _env = env; _env.Tick += EnvTick; }
/// <summary> /// A constructor for the TrackModel module /// </summary> /// <param name="environment">Requires a reference to the surrounding environment object</param> public TrackModel(ISimulationEnvironment environment) { _redLoaded = false; _greenLoaded = false; _env = environment; _dbCreator = new DBCreator("",environment); _dbManager = new DBManager(_dbCreator.DBCon); _changeState = TrackChanged.None; IBlock redTemp = requestBlockInfo(1, "Red"); IBlock greenTemp = requestBlockInfo(1, "Green"); if (redTemp != null) { List<IBlock>[] tempBlockList=createBlockListArray(0); _dbCreator.populateTCs(tempBlockList, true); _changeState = TrackChanged.Red; _redLoaded = true; } if (greenTemp != null) { List<IBlock>[] tempBlockList = createBlockListArray(1); _dbCreator.populateTCs(tempBlockList, false); if (_changeState == TrackChanged.Red) _changeState = TrackChanged.Both; else _changeState = TrackChanged.Green; _greenLoaded = true; } if (_changeState != TrackChanged.None) { alertTrackChanged(); } //_environment.Tick+= }
/// <summary> /// A public constructor allowing external modules or TrackModel to create DBCreator objects /// </summary> /// <param name="fPath">The filepath to the database to connect to</param> public DBCreator(string fPath, ISimulationEnvironment environment) { circuits = new List<ITrackCircuit>(); _env = environment; //fPath is the filename of the database to connect to. //Check filepath's legit'ness, give it the default otherwise if (fPath == null || fPath.Equals("")) { fPath = "trackDatabase.db"; } //Check if the database file exists (before you create it). If it does, we need //to CREATE the necessary tables bool needsInitFlag = false; if (!File.Exists(fPath)) { needsInitFlag = true; } //Create a db connection (creating the db file if it doesnt already exist) //string connectionString = "Data Source=" + fPath; string connectionString="Data Source=" + Path.GetDirectoryName(Application.ExecutablePath)+@"\"+fPath; _dbCon = new SQLiteConnection(connectionString); //If you needed to create the db tables,do so now if (needsInitFlag) { //Console.WriteLine("About to enter initDB"); int initResult = initDB(); //If creating the db failed if (initResult == -1) { _dbCon = null; } } }
/// <summary> /// Construct a new instance of a PLC /// </summary> /// <param name="env">The envrionment </param> /// <param name="circuit">The track circuit for the TrackController</param> public Plc(ISimulationEnvironment env, ITrackCircuit circuit) { _env = env; _circuit = circuit; _broken = new List <IBlock>(); }
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 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 bool DoTest(out int pass, out int fail, out List <string> message) { pass = 0; fail = 0; message = new List <string>(); _environment = new SimulationEnvironment.SimulationEnvironment(); // Create 100 blocks for the red line blocks = new List <IBlock>(); // First block startBlock = new Block(0, StateEnum.Healthy, 99, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 2, 0, 0, "Red", 100); blocks.Add(startBlock); // Next 99 blocks for (var i = 1; i < 99; i++) { blocks.Add(new Block(i, StateEnum.Healthy, i - 1, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, i + 1, 0, 0, "Red", 100)); } // Last block blocks.Add(new Block(99, StateEnum.Healthy, 98, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 100)); _environment.TrackModel = new DummyTrackModel(blocks); // mass test if (TestMass(message)) { pass++; } else { fail++; } // adding passengers test if (TestAddPassengers(message)) { pass++; } else { fail++; } // removing passengers test if (TestRemovePassengers(message)) { pass++; } else { fail++; } // lights test if (TestLights(message)) { pass++; } else { fail++; } // doors test if (TestDoors(message)) { pass++; } else { fail++; } // changing temperature test if (TestTemperature(message)) { pass++; } else { fail++; } // test emergency brake if (TestEmergencyBrake(message)) { pass++; } else { fail++; } // test movement without grade if (TestMovement_NoGrade(message)) { pass++; } else { fail++; } // test movement with positive grade if (TestMovement_PositiveGrade(message)) { pass++; } else { fail++; } // test movement with negative grade if (TestMovement_NegativeGrade(message)) { pass++; } else { fail++; } // test braking during brake failure if (TestBrakeFailureMovement(message)) { pass++; } else { fail++; } // test acceleration during engine failure if (TestEngineFailureMovement(message)) { pass++; } else { fail++; } return(true); }
public bool DoTest(out int pass, out int fail, out List<string> message) { pass = 0; fail = 0; message = new List<string>(); _environment = new SimulationEnvironment.SimulationEnvironment(); // Create 100 blocks for the red line blocks = new List<IBlock>(); // First block startBlock = new Block(0, StateEnum.Healthy, 99, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 2, 0, 0, "Red", 100); blocks.Add(startBlock); // Next 99 blocks for (var i = 1; i < 99; i++) blocks.Add(new Block(i, StateEnum.Healthy, i - 1, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, i + 1, 0, 0, "Red", 100)); // Last block blocks.Add(new Block(99, StateEnum.Healthy, 98, 0, 0, new[] { 0, 0 }, BlockLengh, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 100)); _environment.TrackModel = new DummyTrackModel(blocks); // mass test if (TestMass(message)) pass++; else fail++; // adding passengers test if (TestAddPassengers(message)) pass++; else fail++; // removing passengers test if (TestRemovePassengers(message)) pass++; else fail++; // lights test if (TestLights(message)) pass++; else fail++; // doors test if (TestDoors(message)) pass++; else fail++; // changing temperature test if (TestTemperature(message)) pass++; else fail++; // test emergency brake if (TestEmergencyBrake(message)) pass++; else fail++; // test movement without grade if (TestMovement_NoGrade(message)) pass++; else fail++; // test movement with positive grade if (TestMovement_PositiveGrade(message)) pass++; else fail++; // test movement with negative grade if (TestMovement_NegativeGrade(message)) pass++; else fail++; // test braking during brake failure if (TestBrakeFailureMovement(message)) pass++; else fail++; // test acceleration during engine failure if (TestEngineFailureMovement(message)) pass++; else fail++; return true; }
/// <summary> /// Construct a new instance of a PLC /// </summary> /// <param name="env">The envrionment </param> /// <param name="circuit">The track circuit for the TrackController</param> public Plc(ISimulationEnvironment env, ITrackCircuit circuit) { _env = env; _circuit = circuit; _broken = new List<IBlock>(); }
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 }