private DrawingGroup GetDrawingLayer(DrawingGroup drawingGroup) { DrawingGroup groupDrawing = null; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingGroup.Children) { var itemKey = SvgLink.GetKey(drawing); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return((DrawingGroup)drawing); } // If the drawing is a DrawingGroup, call the function recursively. if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType != SvgObjectType.Text) { var nextGroup = GetDrawingLayer(groupDrawing); if (nextGroup != groupDrawing) { itemKey = SvgLink.GetKey(nextGroup); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return(nextGroup); } } } } } return(drawingGroup); }
// Enumerate the drawings in the DrawingGroup. private void EnumDrawingGroup(DrawingGroup drawingGroup) { // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingGroup.Children) { string objectId = SvgObject.GetId(drawing); if (!string.IsNullOrWhiteSpace(objectId)) { _idMap[objectId] = drawing; } string objectName = (string)drawing.GetValue(FrameworkElement.NameProperty); if (!string.IsNullOrWhiteSpace(objectName)) { _idMap[objectName] = drawing; } string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { _guidMap[uniqueId] = drawing; } DrawingGroup groupDrawing = null; // If the drawing is a DrawingGroup, call the function recursively. if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType != SvgObjectType.Text) { EnumDrawingGroup(groupDrawing); } } } }
private bool HitTestDrawing(DrawingGroup group, Geometry geomDisplay, out Drawing hitDrawing, IntersectionDetail detail) { hitDrawing = null; var geomBounds = new RectangleGeometry(group.Bounds); if (geomBounds.FillContainsWithDetail(geomDisplay) == detail) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { hitDrawing = geometryDrawing; return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { hitDrawing = groupDrawing; return(true); } } if (HitTestDrawing(groupDrawing, geomDisplay, out hitDrawing, detail)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { hitDrawing = glyRunDrawing; return(true); } } } return(true); } return(false); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing) { hitDrawing = null; if (group.Bounds.Contains(pt)) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { hitDrawing = drawing; return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); //if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text) { hitDrawing = drawing; return(true); } if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { hitDrawing = glyRunDrawing; return(true); } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } } return(false); }
private Drawing PerformHitTest(Rect rect, IntersectionDetail detail) { if (_svgDrawing == null) { return(null); } var rectDisplay = _displayTransform.TransformBounds(rect); var geomDisplay = new RectangleGeometry(rectDisplay); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out groupDrawing)) { if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } if (HitTestDrawing(groupDrawing, geomDisplay, out foundDrawing, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { foundDrawing = drawing; break; } } } return(foundDrawing); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing) { hitDrawing = null; bool isHit = false; if (group.Bounds.Contains(pt)) { var transform = group.Transform; if (transform != null) { var matrix = transform.Value; if (matrix != null && matrix.IsIdentity == false) { pt = transform.Inverse.Transform(pt); } } DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); //if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { hitDrawing = glyRunDrawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; isHit = false; } else { return(true); } } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } } return(isHit); }
private Drawing PerformHitTest(Point pt) { _hitGroup = null; if (_hitList == null) { _hitList = new SortedList <int, Drawing>(); } else if (_hitList.Count != 0) { _hitList.Clear(); } if (_svgDrawing == null) { return(null); } Point ptDisplay = _displayTransform.Transform(pt); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, ptDisplay)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { string uniqueId = SvgObject.GetUniqueId(geometryDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out groupDrawing)) { int orderNumber = SvgObject.GetOrder(drawing); if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && groupDrawing.Bounds.Contains(ptDisplay)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { foundDrawing = drawing; break; } } if (HitTestDrawing(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { string uniqueId = SvgObject.GetUniqueId(foundDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { //foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, ptDisplay)) { int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; } else { foundDrawing = drawing; break; } } } } if (_hitList.Count != 0) { return(_hitList.LastOrDefault().Value); } if (foundDrawing == null) { return(_hitGroup); } return(foundDrawing); }
private bool HitTestDrawing(DrawingGroup group, Point pt, out Drawing hitDrawing, bool isText = false) { hitDrawing = null; bool isHit = false; if (!group.Bounds.Contains(pt)) { return(isHit); } var transform = group.Transform; if (transform != null && !transform.Value.IsIdentity) { pt = transform.Inverse.Transform(pt); } var groupHitPath = _hitPath; DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(drawing)); if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, pt)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); isHit = false; } else { orderNumber = SvgObject.GetOrder(group); if (orderNumber >= 0) { _hitList[orderNumber] = group; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(group)); } if (!string.IsNullOrWhiteSpace(SvgObject.GetUniqueId(group))) { _hitGroup = group; } return(true); } } } else if (TryCast.Cast(drawing, out groupDrawing)) { _hitPath = groupHitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); SvgObjectType objectType = SvgObject.GetType(groupDrawing); // if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt)) if (objectType == SvgObjectType.Text && this.HitTestText(groupDrawing, pt, out hitDrawing)) // if (objectType == SvgObjectType.Text) { hitDrawing = drawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath; isHit = false; } else { return(true); } } else { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(hitDrawing)); var currentPath = _hitPath; try { if (HitTestDrawing(groupDrawing, pt, out hitDrawing)) { // int orderNumber = SvgObject.GetOrder(drawing); int orderNumber = SvgObject.GetOrder(hitDrawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(hitDrawing)); isHit = false; } else { orderNumber = SvgObject.GetOrder(groupDrawing); if (orderNumber >= 0) { _hitList[orderNumber] = groupDrawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); } return(true); } } } finally { _hitPath = currentPath; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, pt)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); hitDrawing = glyRunDrawing; int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); isHit = false; } else { return(true); } } } } string uniqueId = SvgObject.GetUniqueId(group); if (!string.IsNullOrWhiteSpace(uniqueId)) { _hitGroup = group; } return(isHit); }
private Drawing PerformHitTest(Point pt) { if (_svgDrawing == null) { return(null); } _hitGroup = null; if (_hitList == null) { _hitList = new SortedList <int, Drawing>(); _hitPaths = new SortedList <int, WpfHitPath>(); } else if (_hitList.Count != 0) { _hitList.Clear(); _hitPaths.Clear(); } var hitRootPath = new WpfHitPath(); _hitPath = hitRootPath; Point ptDisplay = _displayTransform.Transform(pt); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; //var isFound = false; //var drawingLayer = this.GetDrawingLayer(_svgDrawing, ref isFound); //System.Diagnostics.Trace.WriteLine("GetId: " + SvgObject.GetId(drawingLayer)); //System.Diagnostics.Trace.WriteLine("GetName: " + SvgObject.GetName(drawingLayer)); //System.Diagnostics.Trace.WriteLine("GetUniqueId: " + SvgObject.GetUniqueId(drawingLayer)); //DrawingCollection drawings = drawingLayer.Children; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; System.Diagnostics.Trace.WriteLine("GetId: " + SvgObject.GetId(drawing)); System.Diagnostics.Trace.WriteLine("GetName: " + SvgObject.GetName(drawing)); System.Diagnostics.Trace.WriteLine("GetUniqueId: " + SvgObject.GetUniqueId(drawing)); if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, ptDisplay)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(geometryDrawing)); } else { string uniqueId = SvgObject.GetUniqueId(geometryDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } } else if (TryCast.Cast(drawing, out groupDrawing)) { //var ptSaved = ptDisplay; //var transform = groupDrawing.Transform; //if (transform != null && !transform.Value.IsIdentity) //{ // ptDisplay = transform.Inverse.Transform(ptDisplay); //} _hitPath = hitRootPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); int orderNumber = SvgObject.GetOrder(groupDrawing); //if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && // groupDrawing.Bounds.Contains(ptDisplay)) if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text && this.HitTestText(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath; } else { foundDrawing = drawing; break; } } else { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(groupDrawing)); var currentPath = _hitPath; try { if (HitTestDrawing(groupDrawing, ptDisplay, out foundDrawing)) { if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(foundDrawing)); } else { string uniqueId = SvgObject.GetUniqueId(foundDrawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { //foundDrawing = drawing; break; } } } } finally { _hitPath = currentPath; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, ptDisplay)) { // _hitPath = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); int orderNumber = SvgObject.GetOrder(drawing); if (orderNumber >= 0) { _hitList[orderNumber] = drawing; _hitPaths[orderNumber] = _hitPath.AddChild(SvgObject.GetUniqueId(glyRunDrawing)); } else { foundDrawing = drawing; break; } } } } if (_hitList.Count != 0) { var key = _hitList.LastOrDefault().Key; if (_hitPaths.ContainsKey(key)) { System.Diagnostics.Trace.WriteLine("Key Found: " + _hitPaths[key].Path); } return(_hitList.LastOrDefault().Value); } if (foundDrawing == null) { return(_hitGroup); } return(foundDrawing); }