public SimulationViewport(SimulationData data) : base(data.Project) { SimData = data; Vehicles.Dock = DockStyle.Fill; Vehicles.BackColor = Color.Transparent; Vehicles.Paint += DrawVehicles; Nodes.Paint += DrawLights; Grid.Paint -= DrawGrid; Entities.Controls.Remove(Information); Entities.Controls.Add(Vehicles); Vehicles.Controls.Add(Input); Input.BringToFront(); }
static public void SaveSimulation(SimulationData data) { FileStream file = null; try { string path = AppDomain.CurrentDomain.BaseDirectory + "\\" + data.Filename; BinaryFormatter formatter = new BinaryFormatter(); file = new FileStream(path, FileMode.Create); formatter.Serialize(file, data); } catch (Exception e) { MessageBox.Show("Error: " + e.Message); } finally { if (file != null) file.Close(); } }
private void SimulationCompleted(object sender, RunWorkerCompletedEventArgs args) { if (PrimaryWorker.IsBusy || SecondaryWorker.IsBusy || args.Cancelled) return; else { List<VehicleData> primaryData = new List<VehicleData>(); foreach (Vehicle vehicle in _primaryVehicles) primaryData.Add(vehicle.ExtractData()); List<VehicleData> secondaryData = new List<VehicleData>(); foreach (Vehicle vehicle in _secondaryVehicles) secondaryData.Add(vehicle.ExtractData()); SimulationData data = new SimulationData(Project, primaryData, secondaryData); FileHandler.SaveSimulation(data); Filename = data.Filename; OnSimulationDone(); } }