/// <summary> /// Creates canvas with invalidated route and its stops. /// </summary> /// <param name="route">Route to draw.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <param name="mapImage">Map image.</param> /// <returns>Canvas with invalidated route and its stops.</returns> private SysControls.Canvas _CreateRouteCanvas(Route route, IList<Stop> sortedRouteStops, MapImage mapImage) { Debug.Assert(null != route); Debug.Assert(null != mapImage); Debug.Assert(null != sortedRouteStops); // create canvas var canvas = new SysControls.Canvas(); canvas.InvalidateVisual(); canvas.Height = mapImage.ImageHeight; canvas.Width = mapImage.ImageWidth; // init route brush from route color System.Drawing.Color color = route.Color; var mediaColor = SysWindows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); var fillingBrush = new SolidColorBrush(mediaColor); // create and init route image SymbolControl routeBox = new SymbolControl(_routeSymbolTemplate); routeBox.Geometry = _CreatePath(route, sortedRouteStops, mapImage.Extent, mapImage.ImageWidth, mapImage.ImageHeight); routeBox.Fill = (SolidColorBrush)fillingBrush.GetCurrentValueAsFrozen(); routeBox.HorizontalAlignment = HorizontalAlignment.Stretch; routeBox.VerticalAlignment = VerticalAlignment.Stretch; // draw route canvas.Children.Add(routeBox); // draw stops - from last to first (visual elements) int stopLastIndex = sortedRouteStops.Count - 1; for (int index = stopLastIndex; index >= 0; --index) { Stop stop = sortedRouteStops[index]; if (!stop.MapLocation.HasValue) continue; // skip empty bool isVisible = true; if (stop.AssociatedObject is Location) { if (index == 0) { isVisible = _showLeadingStemTime; } else if (index == stopLastIndex) { isVisible = _showTrailingStemTime; } // else do nothing } if (isVisible) { UIElement element = _CreateStopUIElement(stop, mapImage, fillingBrush); if (element != null) canvas.Children.Add(element); } } return canvas; }
/// <summary> /// Renders the contents of the target canvas /// </summary> /// <param name="Canvas">target canvas</param> private void RenderPage(Canvas Canvas) { try { Canvas.Children.RemoveRange(0, Canvas.Children.Count); foreach (PageElement PE in this.CurrentBook.Pages[viewIndex].Children) { ContentControl cc = FormContentControl(PE); cc.Height = PE.Height; cc.Width = PE.Width; if (PE.ControlType == "System.Windows.Controls.RichTextBox") { GenerateTextBox(PE, cc); } else if (PE.ControlType == "System.Windows.Controls.Image") { GenerateImage(PE, cc); } else if (PE.ControlType == "System.Windows.Shapes.Ellipse") { Ellipse e = new Ellipse(); e.Fill = new BrushConverter().ConvertFromString(PE.Child.Brush) as SolidColorBrush; cc.Content = e; } else if (PE.ControlType == "System.Windows.Shapes.Rectangle") { Rectangle r = new Rectangle(); r.Fill = new BrushConverter().ConvertFromString(PE.Child.Brush) as SolidColorBrush; cc.Content = r; } if (!string.IsNullOrWhiteSpace(PE.ControlType)) { Canvas.Children.Add(cc); } } //re-renders the page Canvas.InvalidateVisual(); } catch (Exception ex) { if (ex is ArgumentOutOfRangeException) { host.statuspanel.Background = Brushes.LightCoral; host.lbxstatus.Content = "Error: Page Doesnt Exist"; } } }
/// <summary> /// Creates canvas with invalidated route and its stops. /// </summary> /// <param name="route">Route to draw.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <param name="mapImage">Map image.</param> /// <returns>Canvas with invalidated route and its stops.</returns> private SysControls.Canvas _CreateRouteCanvas(Route route, IList <Stop> sortedRouteStops, MapImage mapImage) { Debug.Assert(null != route); Debug.Assert(null != mapImage); Debug.Assert(null != sortedRouteStops); // create canvas var canvas = new SysControls.Canvas(); canvas.InvalidateVisual(); canvas.Height = mapImage.ImageHeight; canvas.Width = mapImage.ImageWidth; // init route brush from route color System.Drawing.Color color = route.Color; var mediaColor = SysWindows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); var fillingBrush = new SolidColorBrush(mediaColor); // create and init route image SymbolControl routeBox = new SymbolControl(_routeSymbolTemplate); routeBox.Geometry = _CreatePath(route, sortedRouteStops, mapImage.Extent, mapImage.ImageWidth, mapImage.ImageHeight); routeBox.Fill = (SolidColorBrush)fillingBrush.GetCurrentValueAsFrozen(); routeBox.HorizontalAlignment = HorizontalAlignment.Stretch; routeBox.VerticalAlignment = VerticalAlignment.Stretch; // draw route canvas.Children.Add(routeBox); // draw stops - from last to first (visual elements) int stopLastIndex = sortedRouteStops.Count - 1; for (int index = stopLastIndex; index >= 0; --index) { Stop stop = sortedRouteStops[index]; if (!stop.MapLocation.HasValue) { continue; // skip empty } bool isVisible = true; if (stop.AssociatedObject is Location) { if (index == 0) { isVisible = _showLeadingStemTime; } else if (index == stopLastIndex) { isVisible = _showTrailingStemTime; } // else do nothing } if (isVisible) { UIElement element = _CreateStopUIElement(stop, mapImage, fillingBrush); if (element != null) { canvas.Children.Add(element); } } } return(canvas); }