private void LoadLayerDiagrams(DrawingGroup layerGroup) { this.UnloadDiagrams(); DrawingCollection drawings = layerGroup.Children; DrawingGroup drawGroup = null; GeometryDrawing drawGeometry = null; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; if (TryCast(drawing, out drawGroup)) { string groupName = SvgLink.GetKey(drawGroup); if (string.IsNullOrWhiteSpace(groupName)) { groupName = SvgObject.GetId(drawGroup); } //string groupName = SvgObject.GetName(childGroup); if (string.IsNullOrWhiteSpace(groupName)) { LoadLayerGroup(drawGroup); } else { SvgObjectType elementType = SvgObject.GetType(drawGroup); if (elementType == SvgObjectType.Text) { this.AddTextDrawing(drawGroup, groupName); } else { if (drawGroup.Children != null && drawGroup.Children.Count == 1) { this.AddDrawing(drawGroup, groupName); } else { //throw new InvalidOperationException( // String.Format("Error: The link group is in error - {0}", groupName)); } } } } else if (TryCast(drawing, out drawGeometry)) { this.AddGeometryDrawing(drawGeometry); } } if (_drawingCanvas != null) { _displayTransform = _drawingCanvas.DisplayTransform; } }
private void LoadLayerGroup(DrawingGroup group) { DrawingCollection drawings = group.Children; DrawingGroup drawGroup = null; GeometryDrawing drawGeometry = null; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; if (TryCast(drawing, out drawGroup)) { string groupName = SvgLink.GetKey(drawGroup); if (string.IsNullOrWhiteSpace(groupName)) { groupName = SvgObject.GetId(drawGroup); } //string groupName = childGroup.GetValue(FrameworkElement.NameProperty) as string; if (string.IsNullOrWhiteSpace(groupName)) { LoadLayerGroup(drawGroup); } else { SvgObjectType elementType = SvgObject.GetType(drawGroup); if (elementType == SvgObjectType.Text) { this.AddTextDrawing(drawGroup, groupName); } else { if (drawGroup.Children != null && drawGroup.Children.Count == 1) { this.AddDrawing(drawGroup, groupName); } else { //throw new InvalidOperationException( // String.Format("Error: The link group is in error - {0}", groupName)); } } } } else if (TryCast(drawing, out drawGeometry)) { this.AddGeometryDrawing(drawGeometry); } } }
public void RenderDiagrams(DrawingGroup renderedGroup) { DrawingCollection drawings = renderedGroup.Children; int linkIndex = -1; int drawIndex = -1; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; //string drawingName = SvgObject.GetName(drawing); string drawingName = SvgLink.GetKey(drawing); if (!string.IsNullOrWhiteSpace(drawingName) && string.Equals(drawingName, SvgObject.DrawLayer)) { drawIndex = i; } else if (!string.IsNullOrWhiteSpace(drawingName) && string.Equals(drawingName, SvgObject.LinksLayer)) { linkIndex = i; } } DrawingGroup mainGroups = null; if (drawIndex >= 0) { mainGroups = drawings[drawIndex] as DrawingGroup; } DrawingGroup linkGroups = null; if (linkIndex >= 0) { linkGroups = drawings[linkIndex] as DrawingGroup; } this.LoadDiagrams(renderedGroup, linkGroups, mainGroups); if (linkGroups != null) { _animationCanvas.LoadDiagrams(linkGroups, renderedGroup); } _bounds = _wholeDrawing.Bounds; this.InvalidateMeasure(); this.InvalidateVisual(); }
public void RenderDiagrams(DrawingGroup renderedGroup) { DrawingCollection drawings = renderedGroup.Children; int linkIndex = -1; int drawIndex = -1; for (int i = 0; i < drawings.Count; i++) { Drawing drawing = drawings[i]; //string drawingName = drawing.GetValue(FrameworkElement.NameProperty) as string; string drawingName = SvgLink.GetKey(drawing); if (!String.IsNullOrEmpty(drawingName) && String.Equals(drawingName, SvgObject.DrawLayer)) { drawIndex = i; } else if (!String.IsNullOrEmpty(drawingName) && String.Equals(drawingName, SvgObject.LinksLayer)) { linkIndex = i; } } DrawingGroup mainGroups = null; if (drawIndex >= 0) { mainGroups = drawings[drawIndex] as DrawingGroup; } DrawingGroup linkGroups = null; if (linkIndex >= 0) { linkGroups = drawings[linkIndex] as DrawingGroup; } this.LoadDiagrams(renderedGroup, linkGroups, mainGroups); if (linkGroups != null) { _animationCanvas.LoadDiagrams(linkGroups, renderedGroup); } this.InvalidateMeasure(); this.InvalidateVisual(); }
public bool HandleMouseDown(MouseButtonEventArgs e) { Point pt = e.GetPosition(_drawingCanvas); Drawing visual = HitTest(pt); if (visual == null) { if (_tooltip != null) { _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; } return(false); } if (_selectedVisual != null && visual == _selectedVisual) { _drawingCanvas.Cursor = Cursors.Hand; return(true); } string itemName = SvgObject.GetName(visual); if (itemName == null) { if (_tooltip != null) { _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; } return(false); } SolidColorBrush brush = null; if (_visualBrushes.ContainsKey(itemName)) { brush = _visualBrushes[itemName] as SolidColorBrush; if (brush != null) { brush.Color = _colorSelected; } } if (brush == null) { if (_tooltip != null) { _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; } return(false); } if (_selectedVisual != null) { itemName = SvgObject.GetName(_selectedVisual); if (itemName == null) { return(false); } if (_visualBrushes.ContainsKey(itemName)) { brush = _visualBrushes[itemName] as SolidColorBrush; if (brush != null) { brush.Color = _colorLink; } } else { return(false); } } _selectedVisual = visual; if (e.ChangedButton == MouseButton.Left) { string brushName = SvgObject.GetName(brush); if (!string.IsNullOrWhiteSpace(brushName)) { SvgLinkAction linkAction = SvgLink.GetAction(visual); if (linkAction == SvgLinkAction.LinkHtml || linkAction == SvgLinkAction.LinkPage) { _animator.Start(brushName, brush); } } } else if (e.ChangedButton == MouseButton.Right) { _animator.Stop(); } return(true); }
public bool HandleMouseMove(MouseEventArgs e) { // Retrieve the coordinates of the mouse button event. Point pt = e.GetPosition(_drawingCanvas); Drawing hitVisual = HitTest(pt); if (_selectedVisual != null && hitVisual == _selectedVisual) { _drawingCanvas.Cursor = Cursors.Hand; return(true); } string itemName = null; if (hitVisual == null) { if (_hitVisual != null) { itemName = SvgObject.GetName(_hitVisual); if (itemName == null) { _hitVisual = null; return(false); } if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual)) { SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush; if (brush != null) { brush.Color = _colorLink; } } _hitVisual = null; } if (_tooltip != null) { _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; } return(false); } else { _drawingCanvas.Cursor = Cursors.Hand; if (hitVisual == _hitVisual) { return(false); } if (_hitVisual != null) { itemName = SvgObject.GetName(_hitVisual); if (itemName == null) { _hitVisual = null; return(false); } if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual)) { SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush; if (brush != null) { brush.Color = _colorLink; } } _hitVisual = null; } itemName = SvgObject.GetName(hitVisual); if (itemName == null) { return(false); } if (_visualBrushes.ContainsKey(itemName)) { SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush; if (brush != null) { brush.Color = _colorHover; } } _hitVisual = hitVisual; string tooltipText = itemName; SvgLinkAction linkAction = SvgLink.GetAction(hitVisual); if (linkAction == SvgLinkAction.LinkTooltip && _tooltip != null && !string.IsNullOrWhiteSpace(tooltipText)) { Rect rectBounds = hitVisual.Bounds; _tooltip.PlacementRectangle = rectBounds; _tooltipText.Text = tooltipText; if (_tooltip.Visibility == Visibility.Hidden) { _tooltip.Visibility = Visibility.Visible; } _tooltip.IsOpen = true; } else { if (_tooltip != null) { _tooltip.IsOpen = false; _tooltip.Visibility = Visibility.Hidden; } } } return(true); }
public void LoadDiagrams(DrawingGroup linkGroups, DrawingGroup wholeGroup) { if (linkGroups == null) { return; } DrawingCollection drawings = linkGroups.Children; if (drawings == null || drawings.Count == 0) { return; } else if (drawings.Count == 1) { DrawingGroup layerGroup = drawings[0] as DrawingGroup; if (layerGroup != null) { string elementId = SvgObject.GetId(layerGroup); if (!string.IsNullOrWhiteSpace(elementId) && string.Equals(elementId, "IndicateLayer", StringComparison.OrdinalIgnoreCase)) { this.LoadLayerDiagrams(layerGroup); _wholeDrawing = wholeGroup; _linksDrawing = linkGroups; return; } } } this.UnloadDiagrams(); for (int i = 0; i < drawings.Count; i++) { DrawingGroup childGroup = drawings[i] as DrawingGroup; if (childGroup != null) { string groupName = SvgLink.GetKey(childGroup); //string groupName = SvgObject.GetName(childGroup); if (string.IsNullOrWhiteSpace(groupName)) { if (childGroup.Children != null && childGroup.Children.Count == 1) { this.AddDrawing(childGroup); } else { throw new InvalidOperationException("Error: The link group is in error."); } } else { if (childGroup.Children != null && childGroup.Children.Count == 1) { this.AddDrawing(childGroup, groupName); } else { throw new InvalidOperationException( String.Format("Error: The link group is in error - {0}", groupName)); } } } } _wholeDrawing = wholeGroup; _linksDrawing = linkGroups; if (_drawingCanvas != null) { _displayTransform = _drawingCanvas.DisplayTransform; } }