private void insertExternalNeighborLinks(IContainerNode parentContainerNode, GoLayoutForceDirectedNetwork net) { foreach (var childContainerNode in parentContainerNode.GetDirectChildren <IContainerNode>()) { foreach (var neighborhoodNode in childContainerNode.GetLinkedNodes <INeighborhoodNode>()) { if (!parentContainerNode.ContainsChildNode(neighborhoodNode, true)) { var otherContainerNode = neighborhoodNode.GetOtherContainerNode(childContainerNode); var nodeOnBoundary = new GoLayoutForceDirectedNode(); var pos = neighborhoodNode.Location; bool pointExists = GoObject.GetNearestIntersectionPoint(parentContainerNode.Bounds, otherContainerNode.Center, childContainerNode.Center, out pos); if (!pointExists) { continue; } //to be not deleted due to invisible node, seems to set also the position nodeOnBoundary.GoObject = neighborhoodNode as GoObject; nodeOnBoundary.IsFixed = true; nodeOnBoundary.UserFlags = NodeLayoutType.REMOTE_CONTAINER_BOUNDARY_NODE; //set Position after setting GoObject, because setting GoObject seems to set position nodeOnBoundary.Position = pos; net.AddNode(nodeOnBoundary); net.LinkNodes(net.FindNode(childContainerNode as GoObject), nodeOnBoundary, neighborhoodNode as GoObject); } } } }
public void RefreshPort(NeighborLink neighborLink) { if (!_portNodes.ContainsKey(neighborLink)) { return; } var portNode = _portNodes[neighborLink]; var otherContainerNode = neighborLink.NeighborhoodNode.GetOtherContainerNode(this); // set name string name = ""; var otherContainerParentNode = otherContainerNode.GetParent() as IContainerNode; if (otherContainerParentNode != null) { name += otherContainerParentNode.Name + "/"; } name += otherContainerNode.Name; portNode.Name = name; // set position if (portNode.LocationFixed) { return; } PointF borderPosition; RectangleF bounds = ComputeInsideMargins(null); // find points in both containers near to each other float bx = 10; float by = 10; float otherX, otherY, otherWidth, otherHeight; if (neighborLink.NeighborhoodNode.LocationFixed) { otherX = neighborLink.NeighborhoodNode.Location.X; otherY = neighborLink.NeighborhoodNode.Location.Y; otherWidth = bx; otherHeight = by; } else { otherX = otherContainerNode.Center.X; otherY = otherContainerNode.Center.Y; otherWidth = otherContainerNode.Size.Width; otherHeight = otherContainerNode.Size.Height; } float xo = nearestValueFromIntervalCS(otherX, otherWidth, bx, Center.X); float yo = nearestValueFromIntervalCS(otherY, otherHeight, by, Center.Y); float x = nearestValueFromInterval(bounds.Left, bounds.Right, bx, otherX); float y = nearestValueFromInterval(bounds.Top, bounds.Bottom, by, otherY); bool pointExists = GoObject.GetNearestIntersectionPoint(bounds, new PointF(xo, yo), new PointF(x, y), out borderPosition); //Correct by difference between location and center if (pointExists) { var newLocation = borderPosition + new SizeF(portNode.Location.X - portNode.Center.X, portNode.Location.Y - portNode.Center.Y); if (Math.Abs(newLocation.X - portNode.Location.X) > 0.1 || Math.Abs(newLocation.Y - portNode.Location.Y) > 0.1) { portNode.Location = newLocation; foreach (var link in portNode.Links) { ((GoLink)link).UpdateRoute(); } } } }