public void OpenMapFile() { OpenFileDialog openFileDialog_map = new OpenFileDialog(); openFileDialog_map.Filter = "Map Files|*.xml"; openFileDialog_map.Title = "Select a MapDataFile"; if (openFileDialog_map.ShowDialog() == DialogResult.OK) { //Terminate current simulation MainTimer.Stop(); VehicleRunningTimer.Stop(); VehicleGraphicTimer.Stop(); //Initial environment Simulator.Initialize(); Simulator.TaskManager.Initialize(); //Read map file Simulator.mapFilePath = openFileDialog_map.FileName; Simulator.mapFileName = openFileDialog_map.SafeFileName.Substring(0, openFileDialog_map.SafeFileName.LastIndexOf(".")); Simulator.mapFileFolder = Simulator.mapFilePath.Substring(0, Simulator.mapFilePath.LastIndexOf("\\")); SimulatorFileReader sfr = new SimulatorFileReader(); if (Simulator.mapFileReaded = sfr.MapFileRead_XML(openFileDialog_map.FileName)) { this.AddMessage("System", "Read map file : " + openFileDialog_map.SafeFileName + " success!"); Simulator.RoadManager.InitializeRoads_Map(); Simulator.IntersectionManager.InitializeIntersections_Map(); } else { this.AddMessage("System", "Read map file : " + openFileDialog_map.SafeFileName + " fail,the format may be wrong"); } RefreshMapFileStatus(); } }
public void SimulationReset() { if (Simulator.mapFileReaded && currentTask != null) { SimulatorStop(); Simulator.simulatorStarted = false; Simulator.simulatorRun = false; Simulator.VehicleManager.InitializeVehicleManager(); Simulator.DataManager.InitializeDataManager(); //一定要先初始化DM Simulator.IntersectionManager.InitializeIntersections_Simulation(); Simulator.RoadManager.InitializeRoads_Simulation(); Simulator.PrototypeManager.InitialProtype(); vehicleGenerateCounter = 100; IntersectionStatusInitialize(); if (currentTask.simulationFilePath.Equals("")) { Simulator.simulationFileReaded = true; } else { SimulatorFileReader sfr = new SimulatorFileReader(); Simulator.simulationFileReaded = sfr.SimulationFileRead_XML(currentTask.simulationFilePath); } Simulator.setCurrentTime(currentTask.simulationStartTime); this.RefreshSimulationTime(); this.RefreshSimulationFileStatus(); } }