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); } } } }
/// <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); }
/// <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); }