/// <summary> /// Gets the element image in function of his status. /// </summary> /// <param name="element">Element.</param> /// <param name="status">A value indicating if the image must be represented in design mode or working mode.</param> /// <returns>An image representing the element and all his properties.</returns> public Image GetElementImage(Element element, int status) { string imgKey = null; string cacheKey = null; Image image = null; try { imgKey = this.GetResourceName(element, status); cacheKey = string.Format("{0}_{1}", imgKey, (int)element.Rotation); if (this.ImageCache.ContainsKey(cacheKey)) { image = this.ImageCache[cacheKey]; } else { ResourceManager rm = new ResourceManager("Rwm.Otc.Themes.Properties.Resources", Assembly.GetExecutingAssembly()); XmlDocument xml = new XmlDocument(); xml.LoadXml(rm.GetString(imgKey)); SvgDocument svg = SvgDocument.Open(xml); if ((int)element.Rotation > 0) { SvgRotate rotation = new SvgRotate((int)element.Rotation * 90.0f, (float)svg.Height / 2.0f, (float)svg.Width / 2.0f); svg.Transforms.Add(rotation); } image = (Image)svg.Draw(); this.ImageCache.Add(cacheKey, image); } // Print the train name into the block if (element.Properties.IsBlock && element.IsBlockOccupied) { Image imageClone = (Image)image.Clone(); using (Graphics g = Graphics.FromImage(imageClone)) using (Font font = new Font("Calibri", 10)) { g.DrawString(element.Train.Name, font, Brushes.Black, 3, 3); } return(imageClone); } return(image); } catch (Exception ex) { Logger.LogError(this, ex); return(Properties.Resources.ICO_IMAGE_ERROR_32); } }
/// <summary> /// Gets the element image in function of his status. /// </summary> /// <param name="element">Element.</param> /// <param name="designImage">A value indicating if the image must be represented in design mode or working mode.</param> /// <returns>An image representing the element and all his properties.</returns> public Image GetElementImage(Element element, bool designImage) { try { string imgKey = this.GetResourceName(element, designImage); string cacheKey = string.Format("{0}_{1}", imgKey, (int)element.Rotation); Image image; if (this.ImageCache.ContainsKey(cacheKey)) { image = this.ImageCache[cacheKey]; } else { ResourceManager rm = new ResourceManager("Rwm.Otc.Themes.Properties.Resources", Assembly.GetExecutingAssembly()); string xmlSource = rm.GetString(imgKey); if (xmlSource == null) { Logger.LogWarning(this, "THEME WARNING: {0} key not supported in current theme {1}", imgKey, this.Name); return(Properties.Resources.ICO_IMAGE_ERROR_32); } xmlSource = xmlSource.Replace("#NAME", element.Name); XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlSource); SvgDocument svg = SvgDocument.Open(xml); if ((int)element.Rotation > 0) { SvgRotate rotation = new SvgRotate((int)element.Rotation * 90.0f, (float)svg.Height / 2.0f, (float)svg.Width / 2.0f); svg.Transforms.Add(rotation); } image = (Image)svg.Draw(); if (!this.ImageCache.ContainsKey(cacheKey)) { this.ImageCache.Add(cacheKey, image); } else { this.ImageCache[cacheKey] = image; } } // Print the train name into the block if (!designImage && element.Properties.IsBlock && element.IsBlockOccupied) { Image imageClone = (Image)image.Clone(); using (Graphics g = Graphics.FromImage(imageClone)) using (Font font = new Font("Calibri", 10, FontStyle.Bold)) { g.DrawString(element.Train.Name, font, Brushes.Black, 3, 3); } return(imageClone); } else if (designImage && element.Properties.IsBlock) { Image imageClone = (Image)image.Clone(); using (Graphics g = Graphics.FromImage(imageClone)) using (Font font = new Font("Calibri", 10, FontStyle.Bold)) { g.DrawString(element.DisplayName, font, Brushes.Black, 3, 3); } return(imageClone); } return(image); } catch (Exception ex) { Logger.LogError(this, ex); return(Properties.Resources.ICO_IMAGE_ERROR_32); } }