Example #1
0
        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();
        }
Example #3
0
 private void PrevButtonClick(object sender, EventArgs e)
 {
     if (Tc.Previous == null)
     {
         MessageBox.Show("No prior Track Controller!");
     }
     else
     {
         Tc = (TrackController)Tc.Previous;
         Draw();
     }
 }
Example #4
0
 private void NextButtonClick(object sender, EventArgs e)
 {
     if (Tc.Next == null)
     {
         MessageBox.Show("No next Track Controller!");
     }
     else
     {
         Tc = (TrackController)Tc.Next;
         Draw();
     }
 }
Example #5
0
        public void createTrackController()
        {
            IBlock b0 = new Block(0, StateEnum.Healthy, -1, 0, 0, new[] { 0, 0 }, 1000, DirEnum.East, new[] { "" }, 0, 0, 0,
                                  "Green", 70);
            IBlock b1 = new Block(1, StateEnum.Healthy, 0, 0, 0, new[] { 1, 1 }, 1000, DirEnum.East, new[] { "" }, 0, 0, 0,
                                  "Green", 70);
            IBlock b2 = new Block(2, StateEnum.Healthy, 1, 0, 0, new[] { 2, 2 }, 1000, DirEnum.East, new[] { "" }, 0, 0, 0,
                                  "Green", 70);
            IBlock b3 = new Block(3, StateEnum.BrokenTrackFailure, 2, 0, 0, new[] { 3, 3 }, 1000, DirEnum.East, new[] { "" },
                                  0, 0, 0, "Green", 70);

            var sectionA = new List <IBlock>();

            sectionA.Add(b0);
            var sectionB = new List <IBlock>();

            sectionB.Add(b1);
            sectionB.Add(b2);
            var sectionC = new List <IBlock>();

            sectionC.Add(b3);

            // Track Controller
            _currCircuit = new TrackCircuit(_env, sectionA);
            // Next track controller's circuit
            _nextCircuit = new TrackCircuit(_env, sectionB);
            // Previous track controller's circuit
            _prevCircuit = new TrackCircuit(_env, sectionC);

            _prev = new TrackController.TrackController(_env, _prevCircuit);
            _curr = new TrackController.TrackController(_env, _currCircuit);
            _next = new TrackController.TrackController(_env, _nextCircuit);


            _prev.Previous = null;
            _prev.Next     = _curr;

            _curr.Previous = _prev;
            _curr.Next     = _next;

            _next.Previous = _curr;
            _next.Next     = null;

            _env.PrimaryTrackControllerGreen = _prev;
            _env.PrimaryTrackControllerRed   = _prev;
        }
Example #6
0
        private void OkButtonClick(object sender, EventArgs e)
        {
            string i = tcComboBox.SelectedItem.ToString();

            if (String.Compare(i, string.Empty, StringComparison.Ordinal) != 0)
            {
                int controller     = Int32.Parse(i.Split(' ')[2]);
                ITrackController c = _primary;
                while (c != null && c.ID <= controller)
                {
                    Tc = (TrackController)c;
                    c  = c.Next;
                }

                Draw();
            }
        }
Example #7
0
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////

            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] {0, 0}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] {1, 1}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] {2, 2}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] {3, 3}, 10, DirEnum.East, new[] {""}, 0, 0, 0, "Red",70);

            var sectionA = new List<IBlock> {b0};
            var sectionB = new List<IBlock> {b1, b2};
            var sectionC = new List<IBlock> {b3};

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");
            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);

            environment.TrackModel = trackMod;
            prev.Previous = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next = next;

            next.Previous = curr;
            next.Next = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed = prev;

            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form = new Form();
            var control = new UserControl();
            switch (test)
            {
                case 0: // SystemScheduler

                    var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                    control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                    environment.StartTick();
                    break;
                case 1: // CTCOffice
                    environment = null;

                    b0 = null;
                    b1 = null;
                    b2 = null;
                    b3 = null;

                    sectionA = null;
                    sectionB = null;
                    sectionC = null;

                    prevCircuit = null;
                    currCircuit = null;
                    nextCircuit = null;

                    prev = null;
                    curr = null;
                    next = null;

                    trackMod = null;
                    office = null;

                    new CTCGUITest();
                    break;
                case 2: // TrackModel
                    control = new TrackModelGUI(environment, trackMod);
                    break;
                case 3: // TrackController
                    ITrainModel t = new Train(0, b0, environment);

                    environment.AllTrains.Add(t);

                    prevCircuit.Trains.Add(0, t);

                    control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                    break;
                case 4: // TrainModel
                    var loc = new int[2];
                    loc[0] = 10;
                    loc[1] = 10;
                    var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    environment.AddTrain(new Train(0, start, environment));
                    environment.AddTrain(new Train(1, start, environment));

                    var train0 = (Train)environment.AllTrains[0];
                    train0.ChangeMovement(200);

                    control = new TrainGUI(environment);

                    break;
                case 5: // TrainController
                    var loc2 = new int[2];
                    loc2[0] = 10;
                    loc2[1] = 10;
                    var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red",70);
                    var tc = new TrainController.TrainController(environment, new Train(0, start2, environment));
                    control = new TrainControllerUI(tc, environment);
                    break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return null;
            }

            return form;
        }
 private void PrevButtonClick(object sender, EventArgs e)
 {
     if (Tc.Previous == null)
         MessageBox.Show("No prior Track Controller!");
     else
     {
         Tc = (TrackController) Tc.Previous;
         Draw();
     }
 }
        private void OkButtonClick(object sender, EventArgs e)
        {
            string i = tcComboBox.SelectedItem.ToString();
            if (String.Compare(i, string.Empty, StringComparison.Ordinal) != 0)
            {
                int controller = Int32.Parse(i.Split(' ')[2]);
                ITrackController c = _primary;
                while (c != null && c.ID <= controller)
                {
                    Tc = (TrackController)c;
                    c = c.Next;
                }

                Draw();
            }
        }
 private void NextButtonClick(object sender, EventArgs e)
 {
     if (Tc.Next == null)
         MessageBox.Show("No next Track Controller!");
     else
     {
         Tc = (TrackController) Tc.Next;
         Draw();
     }
 }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Environment
            env = new SimulationEnvironment.SimulationEnvironment();

            // TrackModel
            TrackModel.TrackModel trackModel = new TrackModel.TrackModel(env);
            env.TrackModel = trackModel;
            TrackModel.TrackModelGUI trackModelGui = new TrackModelGUI(env, trackModel);

            // CTCOffice
            CTCOffice.CTCOffice ctcOffice = new CTCOffice.CTCOffice(env, env.PrimaryTrackControllerRed, env.PrimaryTrackControllerGreen);
            env.CTCOffice = ctcOffice;
            CTCOffice.CTCOfficeGUI ctcOfficeGui = new CTCOfficeGUI(env, ctcOffice);
            ctcOfficeGui.ShowTrain    += new EventHandler <ShowTrainEventArgs>(ctcOfficeGui_ShowTrain);
            ctcOfficeGui.ShowSchedule += new EventHandler <EventArgs>(ctcOfficeGui_ShowSchedule);


            // Scheduler
            SystemScheduler.SystemScheduler scheduler = new SystemScheduler.SystemScheduler(env, ctcOffice);
            env.SystemScheduler = scheduler;
            SystemScheduler.SystemSchedulerGUI schedulerGui = new SystemScheduler.SystemSchedulerGUI(env, scheduler, ctcOffice);

            // train model form
            TrainModel.TrainGUI trainGui = new TrainGUI(env);

            // Track Controllers
            if (env.PrimaryTrackControllerRed != null)
            {
                TrackController.TrackController red = (TrackController.TrackController)env.PrimaryTrackControllerRed;
                TrackControllerUi redTcGui          = new TrackControllerUi(env, red);
                trackControllerRedForm = new Form()
                {
                    Controls = { redTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Red"
                };
            }

            if (env.PrimaryTrackControllerGreen != null)
            {
                TrackController.TrackController green = (TrackController.TrackController)env.PrimaryTrackControllerGreen;
                TrackControllerUi greenTcGui          = new TrackControllerUi(env, green);
                trackControllerGreenForm = new Form()
                {
                    Controls = { greenTcGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Controller Green"
                };
            }

            ctcForm = new Form()
            {
                Controls = { ctcOfficeGui }, AutoSize = true, Text = "Terminal Velocity - CTC Office"
            };
            schedulerForm = new Form()
            {
                Controls = { schedulerGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - System Scheduler"
            };
            trackModelForm = new Form()
            {
                Controls = { trackModelGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Track Model"
            };
            trainModelForm = new Form()
            {
                Controls = { trainGui }, TopLevel = true, AutoSize = true, Parent = null, Text = "Terminal Velocity - Trains"
            };


            //TODO

            /*
             * Train Controller Form(s)
             * Train Model Form
             */

            ctcForm.Shown += new EventHandler(ctcForm_Shown);

            Application.Run(ctcForm);
        }
        public void createTrackController()
        {
            IBlock b0 = new Block(0, StateEnum.Healthy, -1, 0, 0, new[] {0, 0}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b1 = new Block(1, StateEnum.Healthy, 0, 0, 0, new[] {1, 1}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b2 = new Block(2, StateEnum.Healthy, 1, 0, 0, new[] {2, 2}, 1000, DirEnum.East, new[] {""}, 0, 0, 0,
                                  "Green",70);
            IBlock b3 = new Block(3, StateEnum.BrokenTrackFailure, 2, 0, 0, new[] {3, 3}, 1000, DirEnum.East, new[] {""},
                                  0, 0, 0, "Green",70);

            var sectionA = new List<IBlock>();
            sectionA.Add(b0);
            var sectionB = new List<IBlock>();
            sectionB.Add(b1);
            sectionB.Add(b2);
            var sectionC = new List<IBlock>();
            sectionC.Add(b3);

            // Track Controller
            _currCircuit = new TrackCircuit(_env, sectionA);
            // Next track controller's circuit
            _nextCircuit = new TrackCircuit(_env, sectionB);
            // Previous track controller's circuit
            _prevCircuit = new TrackCircuit(_env, sectionC);

            _prev = new TrackController.TrackController(_env, _prevCircuit);
            _curr = new TrackController.TrackController(_env, _currCircuit);
            _next = new TrackController.TrackController(_env, _nextCircuit);

            _prev.Previous = null;
            _prev.Next = _curr;

            _curr.Previous = _prev;
            _curr.Next = _next;

            _next.Previous = _curr;
            _next.Next = null;

            _env.PrimaryTrackControllerGreen = _prev;
            _env.PrimaryTrackControllerRed = _prev;
        }
        private static Form GuiTestFramework(int test)
        {
            ////////////////////////////////////////////////////////////////////////////////////////
            //                              Initializations                                       //
            ////////////////////////////////////////////////////////////////////////////////////////


            // Environment object
            var environment = new SimulationEnvironment.SimulationEnvironment();

            IBlock b0 = new TrackModel.Block(1, StateEnum.Healthy, 0, 0, 0, new[] { 0, 0 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b1 = new TrackModel.Block(2, StateEnum.Healthy, 1, 0, 0, new[] { 1, 1 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b2 = new TrackModel.Block(3, StateEnum.Healthy, 2, 0, 0, new[] { 2, 2 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);
            IBlock b3 = new TrackModel.Block(4, StateEnum.BrokenTrackFailure, 3, 0, 0, new[] { 3, 3 }, 10, DirEnum.East, new[] { "" }, 0, 0, 0, "Red", 70);

            var sectionA = new List <IBlock> {
                b0
            };
            var sectionB = new List <IBlock> {
                b1, b2
            };
            var sectionC = new List <IBlock> {
                b3
            };

            // Previous track controller's circuit
            var prevCircuit = new TrackCircuit(environment, sectionA);
            // Our track circuit
            var currCircuit = new TrackCircuit(environment, sectionB);
            // Next track controller's circuit
            var nextCircuit = new TrackCircuit(environment, sectionC);

            var prev = new TrackController.TrackController(environment, prevCircuit);
            var curr = new TrackController.TrackController(environment, currCircuit);
            var next = new TrackController.TrackController(environment, nextCircuit);

            //Create TrackModel
            var trackMod = new TrackModel.TrackModel(environment);
            //Let TrackModel read in the lines before you proceed..shouldnt be done this way, but needed to stop CTC Office from faulting
            bool res = trackMod.provideInputFile("red.csv");

            //Console.WriteLine("Res was "+res);
            res = trackMod.provideInputFile("green.csv");
            //Console.WriteLine("Res was " + res);


            environment.TrackModel = trackMod;
            prev.Previous          = null;
            prev.Next = curr;

            curr.Previous = prev;
            curr.Next     = next;

            next.Previous = curr;
            next.Next     = null;

            // Assign the same track controller to both lines
            var office = new CTCOffice.CTCOffice(environment, prev, prev);

            environment.CTCOffice = office;
            environment.PrimaryTrackControllerGreen = prev;
            environment.PrimaryTrackControllerRed   = prev;


            ////////////////////////////////////////////////////////////////////////////////////////
            //                            End Initializations                                     //
            ////////////////////////////////////////////////////////////////////////////////////////

            var form    = new Form();
            var control = new UserControl();

            switch (test)
            {
            case 0:     // SystemScheduler

                var testSystemScheduler = new SystemScheduler.SystemScheduler(environment, office);
                control = new SystemSchedulerGUI(environment, testSystemScheduler, office);
                environment.StartTick();
                break;

            case 1:     // CTCOffice
                environment = null;

                b0 = null;
                b1 = null;
                b2 = null;
                b3 = null;

                sectionA = null;
                sectionB = null;
                sectionC = null;

                prevCircuit = null;
                currCircuit = null;
                nextCircuit = null;

                prev = null;
                curr = null;
                next = null;

                trackMod = null;
                office   = null;

                new CTCGUITest();
                break;

            case 2:     // TrackModel
                control = new TrackModelGUI(environment, trackMod);
                break;

            case 3:     // TrackController
                ITrainModel t = new Train(0, b0, environment);

                environment.AllTrains.Add(t);

                prevCircuit.Trains.Add(0, t);

                control = new TrackControllerUi(environment, environment.PrimaryTrackControllerRed);
                break;

            case 4:     // TrainModel
                var loc = new int[2];
                loc[0] = 10;
                loc[1] = 10;
                var start = new Block(0, StateEnum.Healthy, 0, 0, -0.02, loc, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                environment.AddTrain(new Train(0, start, environment));
                environment.AddTrain(new Train(1, start, environment));

                var train0 = (Train)environment.AllTrains[0];
                train0.ChangeMovement(200);

                control = new TrainGUI(environment);

                break;

            case 5:     // TrainController
                var loc2 = new int[2];
                loc2[0] = 10;
                loc2[1] = 10;
                var start2 = new Block(0, StateEnum.Healthy, 0, 0, 0, loc2, 100, DirEnum.East, null, 1, 2, 0, "Red", 70);
                var tc     = new TrainController.TrainController(environment, new Train(0, start2, environment));
                control = new TrainControllerUI(tc, environment);
                break;
            }

            if (environment != null)
            {
                environment.StartTick();
            }

            if (form != null)
            {
                form.Controls.Add(control);
                form.AutoSize = true;
            }
            else
            {
                return(null);
            }


            return(form);
        }