private void Read(XmlReader reader) { PaintObjectList.Clear(); string MapTransform = ""; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "Map") { size = new Size(int.Parse(reader.GetAttribute("width").Split('.')[0]), int.Parse(reader.GetAttribute("height").Split('.')[0])); continue; } if (reader.Name == "svg") { size = new Size(int.Parse(reader.GetAttribute("width").Split('.')[0]), int.Parse(reader.GetAttribute("height").Split('.')[0])); continue; } if (reader.Name == "g") { MapTransform = reader.GetAttribute("transform"); continue; } if (reader.Name == "path") { PaintObject obj = new PaintObject(reader.Name); obj.AddAttribute("data", reader.GetAttribute("d")); obj.AddAttribute("style", reader.GetAttribute("style")); obj.AddAttribute("transform", reader.GetAttribute("transform")); if (!string.IsNullOrEmpty(MapTransform)) { obj.AddAttribute("maptransform", MapTransform); } PaintObjectList.Add(obj); continue; } if (reader.Name == "rect") { PaintObject obj = new PaintObject(reader.Name); obj.AddAttribute("x", reader.GetAttribute("x")); obj.AddAttribute("y", reader.GetAttribute("y")); obj.AddAttribute("width", reader.GetAttribute("width")); obj.AddAttribute("height", reader.GetAttribute("height")); obj.AddAttribute("style", reader.GetAttribute("style")); obj.AddAttribute("transform", reader.GetAttribute("transform")); if (!string.IsNullOrEmpty(MapTransform)) { obj.AddAttribute("maptransform", MapTransform); } PaintObjectList.Add(obj); } } } reader.Close(); }
public byte[,] GetMap() { Bitmap bmp = new Bitmap(size.Width, size.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); for (int n = 0; n < PaintObjectList.Count; n++) { if (PaintObjectList[n].GetName() == "path") { string data; if (!PaintObjectList[n].TryGetAttributeValue("data", out data)) { continue; } string[] val = data.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); PointF currentPoint = new PointF(); SVSObjectStyle style = PaintObjectList[n].GetStyle(); GraphicsPath path = new GraphicsPath(); for (int i = 0; i < val.Length; i++) { if (val[i] == "m") { i++; currentPoint = StringToPoint(val[i]); while (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } i++; PointF nextPoint = StringToPoint(val[i]); nextPoint.X += currentPoint.X; nextPoint.Y += currentPoint.Y; path.AddLine(currentPoint, nextPoint); currentPoint = nextPoint; } continue; } if (val[i] == "M") { i++; currentPoint = StringToPoint(val[i]); while (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } i++; PointF nextPoint = StringToPoint(val[i]); path.AddLine(currentPoint, nextPoint); currentPoint = nextPoint; } continue; } if (val[i] == "l") { while (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } i++; PointF nextPoint = StringToPoint(val[i]); nextPoint.X += currentPoint.X; nextPoint.Y += currentPoint.Y; path.AddLine(currentPoint, nextPoint); currentPoint = nextPoint; } } if (val[i] == "L") { while (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } i++; PointF nextPoint = StringToPoint(val[i]); path.AddLine(currentPoint, nextPoint); currentPoint = nextPoint; } } if (val[i] == "c") { while (i < val.Length - 1) { PointF bez1 = new PointF(currentPoint.X + StringToPoint(val[i + 1]).X, currentPoint.Y + StringToPoint(val[i + 1]).Y); PointF bez2 = new PointF(currentPoint.X + StringToPoint(val[i + 2]).X, currentPoint.Y + StringToPoint(val[i + 2]).Y); PointF finish = new PointF(currentPoint.X + StringToPoint(val[i + 3]).X, currentPoint.Y + StringToPoint(val[i + 3]).Y); path.AddBezier(currentPoint, bez1, bez2, finish); currentPoint = finish; i += 3; if (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } } } } if (val[i] == "C") { while (i < val.Length - 1) { PointF bez1 = new PointF(StringToPoint(val[i + 1]).X, StringToPoint(val[i + 1]).Y); PointF bez2 = new PointF(StringToPoint(val[i + 2]).X, StringToPoint(val[i + 2]).Y); PointF finish = new PointF(StringToPoint(val[i + 3]).X, StringToPoint(val[i + 3]).Y); path.AddBezier(currentPoint, bez1, bez2, finish); currentPoint = finish; i += 3; if (i < val.Length - 1) { if (val[i + 1].Length == 1) { break; } } } } if (val[i].ToLower() == "a") { i++; PointF point = StringToPoint(val[i]); float w = point.X * 2; float h = point.Y * 2; float x = currentPoint.X - w; float y = currentPoint.Y - h / 2; path.AddEllipse(x, y, w, h); } if (val[i].ToLower() == "z") { break; } } path.Transform(PaintObjectList[n].GetTransformMatrix()); g.FillPath(style.GetBrush(), path); g.DrawPath(style.GetPen(), path); } if (PaintObjectList[n].GetName() == "rect") { float x = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("x")); float y = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("y")); float w = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("width")); float h = PaintObject.StringToFloatConvertor(PaintObjectList[n].GetAttributeValue("height")); SVSObjectStyle style = PaintObjectList[n].GetStyle(); g.Transform = PaintObjectList[n].GetTransformMatrix(); g.FillRectangle(style.GetBrush(), x, y, w, h); g.DrawRectangle(style.GetPen(), x, y, w, h); g.ResetTransform(); } } MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.Position = 0; image = new System.Windows.Media.Imaging.BitmapImage(); image.BeginInit(); image.StreamSource = ms; image.EndInit(); byte[,] map = new byte[size.Width, size.Height]; for (int i = 0; i < size.Width; i++) { for (int j = 0; j < size.Height; j++) { Color color = bmp.GetPixel(i, j); if (color != Color.FromArgb(255, 255, 255, 255)) { map[i, j] |= 0x80; } } } return(map); }
private PointF StringToPoint(string value) { string[] point = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); return(new PointF(Convert.ToSingle(PaintObject.StringToDoubleConvertor(point[0])), Convert.ToSingle(PaintObject.StringToDoubleConvertor(point[1])))); }
public Matrix GetTransformMatrixFromString(string tranform) { if (!string.IsNullOrEmpty(tranform)) { if (tranform.Contains("translate")) { int begin = tranform.IndexOf("(") + 1, end = tranform.IndexOf(")"); string[] values = tranform.Substring(begin, end - begin).Split(','); return(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, PaintObject.StringToFloatConvertor(values[0]), PaintObject.StringToFloatConvertor(values[1]))); } if (tranform.Contains("matrix")) { int begin = tranform.IndexOf("(") + 1, end = tranform.IndexOf(")"); string[] values = tranform.Substring(begin, end - begin).Split(','); return(new System.Drawing.Drawing2D.Matrix( PaintObject.StringToFloatConvertor(values[0]), PaintObject.StringToFloatConvertor(values[1]), PaintObject.StringToFloatConvertor(values[2]), PaintObject.StringToFloatConvertor(values[3]), PaintObject.StringToFloatConvertor(values[4]), PaintObject.StringToFloatConvertor(values[5]))); } } return(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0)); }
public void InitializeStepScenario(ExperimentConfig cnfg) { _scenarioConfig = cnfg; currentTime = cnfg.StartTime; int groupCount = agentGroups.Count; for (int i = 0; i < ServicesList.Count; i++) { if (ServicesList[i] is StopService) { if ((ServicesList[i] as StopService).PassengersGroup != null) { groupCount++; } } if (ServicesList[i] is TurnstileService) { if ((ServicesList[i] as TurnstileService).TurnstileGeometry != null) { PaintObject obj = new PaintObject(ServicesList[i].Name); } } ServicesList[i].Initialize(); } _analisisViewModel = new AnalisisViewModel(); _analisis = new AnalisisCollector(map.GetMap().GetLength(0), map.GetMap().GetLength(1), groupCount); if (GroupListeners != null) { foreach (var listener in GroupListeners.Values) { listener.Stop(); } } GroupListeners = new Dictionary<int, TcpListener>(); ServersSocketList = new Dictionary<int, Socket>(); agentsList = new List<AgentBase>(); AgentByStepCounter = new Dictionary<int, double>(); for (int i = 0; i < agentGroups.Count;i++ ) { if (agentGroups[i].IsNetworkGroup) { TcpListener tcpListener = new TcpListener(System.Net.IPAddress.Parse(agentGroups[i].Address), agentGroups[i].Port); tcpListener.Start(); GroupListeners.Add(agentGroups[i].ID, tcpListener); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(AcceptAgent_DoWork); worker.RunWorkerAsync(agentGroups[i]); } else { AgentByStepCounter.Add(agentGroups[i].ID, 0); } } }