Example #1
0
        IEnumerable <object> IPickingAdapter.Pick(Region region)
        {
            if (m_annotatedDiagram == null)
            {
                return(EmptyEnumerable <object> .Instance);
            }

            List <object> hit = new List <object>();
            RectangleF    bounds;

            using (Graphics g = AdaptedControl.CreateGraphics())
                bounds = region.GetBounds(g);

            if (m_transformAdapter != null)
            {
                bounds = GdiUtil.InverseTransform(m_transformAdapter.Transform, bounds);
            }

            foreach (IAnnotation annotation in m_annotatedDiagram.Annotations)
            {
                Rectangle annotationBounds = GetBounds(annotation);
                if (bounds.IntersectsWith(annotationBounds))
                {
                    hit.Add(annotation);
                }
            }

            return(hit);
        }
Example #2
0
        /// <summary>
        /// Gets the bounding rectangle of the nodes in client coordinates</summary>
        /// <param name="nodes">Graph nodes</param>
        /// <returns>Bounding rectangle of nodes</returns>
        public Rectangle GetBounds(IEnumerable <TNode> nodes)
        {
            Rectangle bounds;

            using (Graphics g = AdaptedControl.CreateGraphics())
            {
                g.Transform = m_transformAdapter.Transform;
                bounds      = m_renderer.GetBounds(nodes, g);
            }
            return(bounds);
        }
Example #3
0
        /// <summary>
        /// Performs a picking operation and returns enumeration of Nodes intersecting the region</summary>
        /// <param name="pickRegion">Hit test region</param>
        /// <typeparam name="T">Type of objects intersecting pick region</typeparam>
        /// <returns>Objects of type T intersecting the pick region</returns>
        /// <remarks>The default implementation only returns intersecting Nodes, but derived
        /// classes can override this method to return Edges or EdgeRoutes as well.</remarks>
        public virtual IEnumerable <T> Pick <T>(Region pickRegion) where T : class
        {
            List <TNode> pickedGraphNodes = new List <TNode>();

            using (Graphics g = AdaptedControl.CreateGraphics())
            {
                RectangleF pickRect = pickRegion.GetBounds(g);
                pickRect = GdiUtil.InverseTransform(m_transformAdapter.Transform, pickRect);
                foreach (TNode node in m_graph.Nodes)
                {
                    RectangleF nodeBounds = m_renderer.GetBounds(node, g);
                    if (nodeBounds.IntersectsWith(pickRect))
                    {
                        pickedGraphNodes.Add(node);
                    }
                }
            }

            return(pickedGraphNodes.AsIEnumerable <T>());
        }
Example #4
0
        /// <summary>
        /// Performs a picking operation on the graph with the point</summary>
        /// <param name="p">Hit test point</param>
        /// <returns>Hit record resulting from picking operation</returns>
        public GraphHitRecord <TNode, TEdge, TEdgeRoute> Pick(Point p)
        {
            // use cache to speed up multiple pick requests at the same point
            if (m_cachedHitRecord == null || p != m_cachedHitPoint)
            {
                m_cachedHitPoint = p;

                TEdge priorityEdge = null;
                if (m_selectionContext != null)
                {
                    priorityEdge = m_selectionContext.GetLastSelected <TEdge>();
                }

                p = GdiUtil.InverseTransform(m_transformAdapter.Transform, p);
                using (Graphics g = AdaptedControl.CreateGraphics())
                {
                    m_cachedHitRecord = m_renderer.Pick(m_graph, priorityEdge, p, g);
                }
            }

            return(m_cachedHitRecord);
        }