override protected void CollectGridSnapResults(GraphSnapContext context, CollectSnapResultsEventArgs args, RectD suggestedLayout, INode node)
        {
            // node.Layout isn't updated, yet, so we have to calculate the delta between the the new suggested layout and the current node.Layout
            PointD delta = suggestedLayout.TopLeft - node.Layout.GetTopLeft();

            // get outline of the shape and iterate over it's path point
            IShapeGeometry geometry = node.Style.Renderer.GetShapeGeometry(node, node.Style);
            GeneralPath    outline  = geometry.GetOutline();

            if (outline != null)
            {
                GeneralPath.PathCursor cursor = outline.CreateCursor();
                while (cursor.MoveNext())
                {
                    // ignore PathType.Close as we had the path point as first point
                    // and cursor.CurrentEndPoint is always (0, 0) for PathType.Close
                    if (cursor.PathType != PathType.Close)
                    {
                        // adjust path point by the delta calculated above and add an according SnapResult
                        PointD endPoint = cursor.CurrentEndPoint + delta;
                        AddGridSnapResultCore(context, args, endPoint, node, GridSnapTypes.GridPoints, SnapPolicy.ToNearest, SnapPolicy.ToNearest);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the intersection point of the segment between the outer and inner point and the node's rotated shape.
        /// </summary>
        /// <remarks>
        /// If there is no intersection point, the result is null.
        /// </remarks>
        protected override PointD?GetIntersection(INode node, IShapeGeometry nodeShapeGeometry, IEdge edge, PointD inner, PointD outer)
        {
            var a = GetScaledOutline(node, nodeShapeGeometry).FindLineIntersection(inner, outer);

            if (a < Double.PositiveInfinity)
            {
                return(inner + (outer - inner) * a);
            }
            return(null);
        }
            /// <summary>
            /// Use the node style's outline as obstacle.
            /// </summary>
            /// <remarks>For node style renderers that don't provide a <see cref="IShapeGeometry"/>, no bridges will be created.</remarks>
            /// <returns></returns>
            private GeneralPath CreatePath()
            {
                INodeStyle     style    = groupNode.Style;
                IShapeGeometry geometry = style.Renderer.GetShapeGeometry(groupNode, style);

                if (geometry != null)
                {
                    GeneralPath outline = geometry.GetOutline();
                    return(outline);
                }
                return(null);
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a slightly enlarged outline of the shape to ensure that ports that lie exactly on the shape's outline
        /// are always considered inside.
        /// </summary>
        private GeneralPath GetScaledOutline(INode node, IShapeGeometry nodeShapeGeometry)
        {
            var outline = nodeShapeGeometry.GetOutline();

            if (outline == null)
            {
                outline = new GeneralPath(4);
                outline.AppendRectangle(node.Layout.ToRectD(), false);
            }
            const double factor = 1.001;
            var          center = node.Layout.GetCenter();
            var          matrix = new Matrix2D();

            matrix.Translate(new PointD(-center.X * (factor - 1), -center.Y * (factor - 1)));
            matrix.Scale(factor, factor);
            outline.Transform(matrix);
            return(outline);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Checks whether or not the given location is inside the nodes rotated shape.
 /// </summary>
 protected override bool IsInside(PointD location, INode node, IShapeGeometry nodeShapeGeometry, IEdge edge)
 {
     return(GetScaledOutline(node, nodeShapeGeometry).AreaContains(location));
 }