//public static List<ElementDescription> foo(RoomInfo location) //{ // try // { // StreamResourceInfo xml = Application.GetResourceStream(new Uri( // "Maps/" + location.Building + "-" + location.Floor + ".svg", UriKind.Relative)); // string svgDocContent = new StreamReader(xml.Stream).ReadToEnd(); // return foo(location, svgDocContent); // } // catch (Exception e) // { // throw new Exception("Could not load the map for " + // "building '" + location.Building + "', " + // "floor'" + location.Floor + "'\n" + e.Message); // } //} public static List<ElementDescription> foo(RoomInfo location, string svgDocContent) { var elements = new List<ElementDescription>(); XElement doc = null; try { doc = XDocument.Parse(svgDocContent).Root; } catch (Exception e) { throw new Exception("Could not load the map for " + "building '" + location.Building + "', " + "floor'" + location.Floor + "'\n" + e.Message); } foreach (XElement node in doc.Nodes().OfType<XElement>()) { foreach (XElement node2 in node.Nodes().OfType<XElement>()) { elements.Add(ParseSvgElement(node2, node.Attribute("id").Value)); } } elements = elements.Where(p => p != null).ToList(); return elements; }
public XamlMapInfo(RoomInfo location, string svgDocContent) { elements = SvgParser.foo(location, svgDocContent); foreach (var description in elements) { switch (description.Type) { case ElementType.Circle: buildingBounds.UpdateBounds(description.CenterX, description.CenterY); break; case ElementType.Text: buildingBounds.UpdateBounds(description.CenterX, description.CenterY); int roomNumber; if (int.TryParse(description.Text, out roomNumber)) { RoomLocations.Add(roomNumber, new Point(description.CenterX, description.CenterY)); } break; case ElementType.Path: default: break; } } }
public void Render(Canvas funky, Canvas parent, Canvas window, CompositeTransform textRotation, Action<Action> dispatcher, RoomInfo location) { dispatcher(() => { CompositeTransform c = (CompositeTransform)funky.RenderTransform; c.CenterX = buildingBounds.CenterX; c.CenterY = buildingBounds.CenterY; funky.Width = buildingBounds.Width; funky.Height = buildingBounds.Height; c.TranslateX = -buildingBounds.CenterX + window.ActualWidth / 2; c.TranslateY = -buildingBounds.CenterY + window.ActualHeight / 2; }); foreach (var description in elements.Where(p => p.Parent == ParentType.Labels || p.Parent == ParentType.Rooms)) { this.checkRunActions(50, () => RenderElement(parent, textRotation, description), dispatcher); } // Highlight the correct room this.checkRunActions(1, () => { var roomElement = parent.Children.OfType<Path>().FirstOrDefault(p => ToInt(p.Tag as string) == location.Room); if (roomElement != null) { roomElement.Fill = new SolidColorBrush(Colors.Magenta); } }, dispatcher); foreach (var description in elements.Where(p => p.Parent == ParentType.Background)) { // Fewer because these paths are more complex this.checkRunActions(5, () => RenderElement(parent, textRotation, description), dispatcher); } this.checkRunActions(0, () => { }, dispatcher); }