internal Scenario ReadScenario() { Scenario sim = new Scenario(); try { using (StreamReader test = new StreamReader(_path + "scenario.scn")) {} } catch (Exception) { return null; } try { using (StreamReader sr = new StreamReader(_path + "map.svg")) { sim.StringMap = sr.ReadToEnd(); XmlTextReader reader = new XmlTextReader(_path + "map.svg"); MapReader mapreader = new MapReader(reader); byte[,] temp = mapreader.GetMap(); sim.map = new MapOld(temp); for (int i = 0; i < temp.GetLength(0); i++) { for (int j = 0; j < temp.GetLength(1); j++) { if ((temp[i, j] & 0x80) != 0x80) { sim.MapSquere += MapOld.CellSize * MapOld.CellSize; } } } sim.paintObjectList = mapreader.GetPaintObjectList(); sim.Image = mapreader.GetImage(); } } catch (System.IO.FileNotFoundException) { sim.map = new MapOld(600, 300); sim.paintObjectList = new List<PaintObject>(); sim.Image = new System.Windows.Media.Imaging.BitmapImage(); } try { using (StreamReader reader = new StreamReader(_path + "AgentGroups.xml")) { XmlSerializer sw = new XmlSerializer(typeof(AgentsGroup[])); AgentsGroup[] groups = (AgentsGroup[])sw.Deserialize(reader); sim.agentGroups = new List<AgentsGroup>(groups); } } catch (System.IO.FileNotFoundException) { sim.agentGroups = new List<AgentsGroup>(); } try { using (StreamReader reader = new StreamReader(_path + "Services.xml")) { XmlSerializer sw = new XmlSerializer(typeof(ServiceBase[]), new Type[] { typeof(StopService), typeof(TurnstileService), typeof(QueueService), typeof(System.Windows.Media.LineSegment), typeof(System.Windows.Media.PolyLineSegment), typeof(System.Windows.Media.BezierSegment) }); ServiceBase[] services = (ServiceBase[])sw.Deserialize(reader); sim.ServicesList = new List<ServiceBase>(services); } } catch (System.IO.FileNotFoundException) { sim.ServicesList = new List<ServiceBase>(); } try { using (StreamReader reader = new StreamReader(_path + "RoadGraph.xml")) { XmlSerializer sw = new XmlSerializer(typeof(GraphContainer)); GraphContainer graph = (GraphContainer)sw.Deserialize(reader); Graph<WayPoint, System.Windows.Media.PathFigure> roadGraph = new Graph<WayPoint, System.Windows.Media.PathFigure>(); for (int i = 0; i < graph.VertecesList.Count; i++) { roadGraph.Add(graph.VertecesList[i]); } for (int i = 0; i < graph.EdgesList.Count; i++) { roadGraph.AddEdge(graph.VertecesList[graph.EdgesList[i].from_id], graph.VertecesList[graph.EdgesList[i].to_id], graph.EdgesList[i].data); } sim.RoadGraph = roadGraph; } } catch (System.IO.FileNotFoundException) { Console.WriteLine("Can't load Road Graph"); sim.RoadGraph = new Graph<WayPoint, System.Windows.Media.PathFigure>(); } sim.agentsList = new List<AgentBase>(); int last_agent_id = 0, last_service_id = 0, last_group_id = 0; for (int i = 0; i < sim.agentGroups.Count; i++) { if (last_group_id < sim.agentGroups[i].ID) { last_group_id = sim.agentGroups[i].ID; } } for (int i = 0; i < sim.ServicesList.Count; i++) { if (last_service_id < sim.ServicesList[i].ID) { last_service_id = sim.ServicesList[i].ID; } sim.ServicesList[i].scenario = sim; if (sim.ServicesList[i] is StopService) { try { if (last_group_id < (sim.ServicesList[i] as StopService).PassengersGroup.ID) { last_group_id = (sim.ServicesList[i] as StopService).PassengersGroup.ID; } } catch { } } } AgentIDEnumerator.Init(last_agent_id); GroupIDEnumerator.Init(last_group_id); ServiceIDEnumerator.Init(last_service_id); return sim; }
internal Scenario ReadScenario() { Scenario sim = new Scenario(); try { using (StreamReader test = new StreamReader(_path + "scenario.scn")) {} } catch (Exception) { return(null); } try { using (StreamReader sr = new StreamReader(_path + "map.svg")) { sim.StringMap = sr.ReadToEnd(); XmlTextReader reader = new XmlTextReader(_path + "map.svg"); MapReader mapreader = new MapReader(reader); byte[,] temp = mapreader.GetMap(); sim.map = new MapOld(temp); for (int i = 0; i < temp.GetLength(0); i++) { for (int j = 0; j < temp.GetLength(1); j++) { if ((temp[i, j] & 0x80) != 0x80) { sim.MapSquere += MapOld.CellSize * MapOld.CellSize; } } } sim.paintObjectList = mapreader.GetPaintObjectList(); sim.Image = mapreader.GetImage(); } } catch (System.IO.FileNotFoundException) { sim.map = new MapOld(600, 300); sim.paintObjectList = new List <PaintObject>(); sim.Image = new System.Windows.Media.Imaging.BitmapImage(); } try { using (StreamReader reader = new StreamReader(_path + "AgentGroups.xml")) { XmlSerializer sw = new XmlSerializer(typeof(AgentsGroup[])); AgentsGroup[] groups = (AgentsGroup[])sw.Deserialize(reader); sim.agentGroups = new List <AgentsGroup>(groups); } } catch (System.IO.FileNotFoundException) { sim.agentGroups = new List <AgentsGroup>(); } try { using (StreamReader reader = new StreamReader(_path + "Services.xml")) { XmlSerializer sw = new XmlSerializer(typeof(ServiceBase[]), new Type[] { typeof(StopService), typeof(TurnstileService), typeof(QueueService), typeof(System.Windows.Media.LineSegment), typeof(System.Windows.Media.PolyLineSegment), typeof(System.Windows.Media.BezierSegment) }); ServiceBase[] services = (ServiceBase[])sw.Deserialize(reader); sim.ServicesList = new List <ServiceBase>(services); } } catch (System.IO.FileNotFoundException) { sim.ServicesList = new List <ServiceBase>(); } try { using (StreamReader reader = new StreamReader(_path + "RoadGraph.xml")) { XmlSerializer sw = new XmlSerializer(typeof(GraphContainer)); GraphContainer graph = (GraphContainer)sw.Deserialize(reader); Graph <WayPoint, System.Windows.Media.PathFigure> roadGraph = new Graph <WayPoint, System.Windows.Media.PathFigure>(); for (int i = 0; i < graph.VertecesList.Count; i++) { roadGraph.Add(graph.VertecesList[i]); } for (int i = 0; i < graph.EdgesList.Count; i++) { roadGraph.AddEdge(graph.VertecesList[graph.EdgesList[i].from_id], graph.VertecesList[graph.EdgesList[i].to_id], graph.EdgesList[i].data); } sim.RoadGraph = roadGraph; } } catch (System.IO.FileNotFoundException) { Console.WriteLine("Can't load Road Graph"); sim.RoadGraph = new Graph <WayPoint, System.Windows.Media.PathFigure>(); } sim.agentsList = new List <AgentBase>(); int last_agent_id = 0, last_service_id = 0, last_group_id = 0; for (int i = 0; i < sim.agentGroups.Count; i++) { if (last_group_id < sim.agentGroups[i].ID) { last_group_id = sim.agentGroups[i].ID; } } for (int i = 0; i < sim.ServicesList.Count; i++) { if (last_service_id < sim.ServicesList[i].ID) { last_service_id = sim.ServicesList[i].ID; } sim.ServicesList[i].scenario = sim; if (sim.ServicesList[i] is StopService) { try { if (last_group_id < (sim.ServicesList[i] as StopService).PassengersGroup.ID) { last_group_id = (sim.ServicesList[i] as StopService).PassengersGroup.ID; } } catch { } } } AgentIDEnumerator.Init(last_agent_id); GroupIDEnumerator.Init(last_group_id); ServiceIDEnumerator.Init(last_service_id); return(sim); }